0
我有一個自定義標題欄。這是樣式部分。Android自定義標題欄視圖未正確對齊
<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);
}
這裏的類是如何出現的:
我proble m是那兩個imageviews
(衛星)應該對齊到左邊和右邊。我似乎無法做到這一點。
有沒有人有一個想法,爲什麼他們沒有對齊?
它正確地顯示在Eclipse
的圖形佈局中,但是當我在模擬器和我的物理設備上運行它時,它就像圖片一樣顯示出來。我應該提到我的活動擴展CustomTitle。
我無法讓它與線性佈局一起工作,雖然實際的佈局工作,謝謝。 –