-2
 <View
    android:layout_width="1dp"
    android:layout_height="30dp" >
</View>

<LinearLayout
    android:layout_width="match_parent" 
    android:layout_height="35dip"
    android:background="#397921"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/headertitle"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left"
        android:textColor="#ffffff"
        android:paddingLeft="8dp"
         />
</LinearLayout>

我有这样的标题,我将如何在右上角添加图像或按钮。

4

2 回答 2

1
<RelativeLayout
    android:layout_width="match_parent" 
    android:layout_height="35dip"
    android:background="#397921"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/headertitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_alignParentLeft="true"
        android:gravity="left"
        android:textColor="#ffffff"
        android:paddingLeft="8dp"
         />

    <ImageView 
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:background="@drawable/icon"/>
</RelativeLayout>
于 2013-04-19T06:54:05.473 回答
1

使用相对布局,您可以在其中相对于父级排列子级。

代码提示:

<RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/header" //Your background header
    android:id="@+id/header"
   >
   <ImageView 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentRight="true"
     android:layout_marginRight="10dp"
     android:background="@drawable/logout" //Your background image
     android:layout_centerVertical="true" 
     android:id="@+id/logout"  
     />  

   </RelativeLayout>    
于 2013-04-19T06:53:42.737 回答