2011-12-20 66 views
3

我目前正在制作一个android应用程序,我使用了标题栏,因此标题栏的所有内容都保存在window_title.xml中,我已将LinearLayout设置为:paddingLeft =“5dip”。现在我需要加载一个imageView在这个titleBar的右侧,我怎么能够覆盖这个paddingLeft我不能删除它,因为它需要左边的文本和图像,但我也需要它在右边...在Android上的LinearLayout中覆盖paddingLeft

这是当前xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="50dip" 
    android:gravity="center_vertical" 
    android:paddingLeft="5dip" 
    android:background="#222222"> 

    <ImageView 
     android:id="@+id/header" 
     android:src="@drawable/header" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/>  

    <TextView   
     android:text="TextTexast" 
     android:textSize="10pt" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:paddingLeft="5dip" 
     android:textColor="#F7F7F7" 
     /> 

</LinearLayout> 

回答

3

如果我正确理解你的问题,你正在寻找一些填充适用于您显示给TextView的标题栏的右侧的ImageView的。你可以在你的根LinearLayout使用android:paddingRight这样的:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="50dip" 
    android:gravity="center_vertical" 
    android:paddingLeft="5dip" 
    android:paddingRight="5dip 
    android:background="#222222"> 

或者,您可以指定要右对齐的ImageViewandroid:paddingRight属性。

+0

尝试像那样。但还是一样的。这里有图片可以帮助你:http://shrani.si/f/k/r5/2y9AMubw/img.png所以我需要将这个灰色的形状从左上角移到右下角。正如我在LinearLayout paddingRight中它只是忽略了我在ImageView中指定的内容。 – HyperX 2011-12-20 20:57:36

+1

因此,如果它不适合你@HyperX,你为什么将它标记为接受的答案? – StackOverflowed 2012-07-06 10:05:29

0

要将灰色图移动到右侧,请将android:layout_gravity设置为"right"