[英]Android Custom Title Bar views not aligning correctly
我有一個自定義標題欄。 這是樣式部分。
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:padding">0px</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
<item name="android:windowBackground">@drawable/gradient</item>
</style>
這是XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#323331"
android:orientation="horizontal" >
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:src="@drawable/satellite" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/satellite" />
</LinearLayout>
</LinearLayout>
這是該XML的類
public class CustomTitle extends Activity {
protected TextView title;
protected ImageView icon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.customtitle);
title = (TextView) findViewById(R.id.title);
icon = (ImageView) findViewById(R.id.icon);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
}
它的外觀如下:
我的問題是,這兩個imageviews
(衛星)應該與左側和右側對齊。 我似乎無法做到這一點。
有誰知道為什么他們不結盟?
它在Eclipse
的圖形布局中正確顯示,但是當我在模擬器和物理設備上運行它時,它就像圖片一樣顯示。 我應該提到我的活動擴展了CustomTitle。
從圖像視圖和linearlayout中刪除layout_weight。 也要使用重力,而不要使用layout_gravity。 我認為(我目前沒有電腦)可以解決您的問題。 您可以使用的另一種方法是使用相對布局作為根布局,而不是第一個linearlayout,並在圖像視圖和第二個linearlayout上使用AlignParentLeft和alignParentRight。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.