2013-09-28 42 views
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); 

} 

这里的类是如何出现的:

http://imgur.com/0y5SANf

我proble m是那两个imageviews(卫星)应该对齐到左边和右边。我似乎无法做到这一点。

有没有人有一个想法,为什么他们没有对齐?

它正确地显示在Eclipse的图形布局中,但是当我在模拟器和我的物理设备上运行它时,它就像图片一样显示出来。我应该提到我的活动扩展CustomTitle。

回答

0

从图像视图和线性布局中移除layout_weight。也使用重力而不是layout_gravity。我认为(我目前没有我的电脑),这应该可以解决您的问题。您可以使用的另一条路线是使用相对布局作为根布局而不是第一个线性布局,并在图像视图和第二个线性布局上使用alignParentLeft和alignParentRight。

+0

我无法让它与线性布局一起工作,虽然实际的布局工作,谢谢。 –