Android XML 中的对齐问题



我想在我的标题上添加后退按钮和分隔符,我已经使用了线性布局,有什么办法可以在不对代码进行重大更改的情况下做到这一点?以下是屏幕截图和代码:

后退按钮和分隔符代码:

 <ImageView
            android:id="@+id/back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:src="@drawable/back"/>
<ImageView
            android:id="@+id/backdivider"
            android:layout_width="2dip"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp"
            android:layout_toRightOf="@+id/back"
            android:background="#85929B" 
            android:paddingBottom="15dip"
            android:paddingTop="15dip" />

完整代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e7ebee"
    android:gravity="center"
    android:orientation="vertical" 
    android:weightSum="1">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="452dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">
        BACK BUTTON
        DIVIDER

        <ImageView
            android:id="@+id/windowtitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#0a2436"
            android:gravity="center_horizontal|center_vertical"
            android:paddingBottom="10dip"
            android:paddingTop="10dip"
            android:src="@drawable/logo" >
        </ImageView>
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:divider="@android:color/darker_gray"
            android:dividerHeight="1dip"
            android:drawSelectorOnTop="false"
            android:focusable="false"
            android:paddingTop="0dip" />
        <!--  android:divider="@color/listDivider" -->
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1">
    <TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:gravity="bottom"
     >
    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#092435"
        android:gravity="center_horizontal" >
        <Button
            android:id="@+id/btnManualLookup"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#4982AE"
            android:gravity="center"
            android:padding="15dip"
            android:text="Activity"
            android:textColor="#ffffff" />
        <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_marginTop="6dip"
            android:layout_marginBottom="6dip"
            android:background="#85929B" />
        <Button
            android:id="@+id/supportbutton"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#092435"
            android:gravity="center"
            android:padding="15dip"
            android:text="Support"
            android:textColor="#ffffff" />
         <View
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:layout_marginTop="6dip"
            android:layout_marginBottom="6dip"
            android:background="#85929B" />
        <Button
            android:id="@+id/messagebutton"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:background="#092435"
            android:gravity="center"
            android:padding="15dip"
            android:text="Messages"
            android:textColor="#ffffff" />
    </TableRow>
 </TableLayout>
</LinearLayout>
</LinearLayout>

把这个代码放在分隔符上

水平线

<View
   android:id="@+id/view"
   android:background="#FF4500"
   android:layout_width="fill_parent"
   android:layout_height="2dp"     
   android:layout_below="@+id/listview_id" />

垂直线

<View
   android:id="@+id/view"
   android:background="#FF4500"
   android:layout_width="2dp"
   android:layout_height="fill_parent"     />

您的 xml 更改如下所示

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e7ebee"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <ImageView
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />
    <ImageView
        android:id="@+id/backdivider"
        android:layout_width="2dip"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:layout_toRightOf="@+id/back"
        android:background="#85929B"
        android:paddingBottom="15dip"
        android:paddingTop="15dip" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="452dp"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/windowtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#0a2436"
        android:gravity="center_horizontal|center_vertical"
        android:paddingBottom="10dip"
        android:paddingTop="10dip" >
    </ImageView>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="1dip"
        android:drawSelectorOnTop="false"
        android:focusable="false"
        android:paddingTop="0dip" />
    <!-- android:divider="@color/listDivider" -->
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center" >
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:gravity="bottom" >
        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#092435"
            android:gravity="center_horizontal" >
            <Button
                android:id="@+id/btnManualLookup"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#4982AE"
                android:gravity="center"
                android:padding="15dip"
                android:text="Activity"
                android:textColor="#ffffff" />
            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="6dip"
                android:layout_marginTop="6dip"
                android:background="#85929B" />
            <Button
                android:id="@+id/supportbutton"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#092435"
                android:gravity="center"
                android:padding="15dip"
                android:text="Support"
                android:textColor="#ffffff" />
            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="6dip"
                android:layout_marginTop="6dip"
                android:background="#85929B" />
            <Button
                android:id="@+id/messagebutton"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:background="#092435"
                android:gravity="center"
                android:padding="15dip"
                android:text="Messages"
                android:textColor="#ffffff" />
        </TableRow>
    </TableLayout>
   </LinearLayout>
  </LinearLayout>

Put

<View android:layout_width="2dip"
      android:layout_height="wrap_content"
      android:background="#0a2436"/>

它不是最好的解决方案,但你最好,因为你说你不想对代码进行太多修改。

最新更新