Android:布局列表标题

Epi*_*aos 2 android android-layout android-linearlayout

我有一个包含两个图像按钮的列表标题.我希望其中一个图像按钮位于左侧,另一个位于右侧.这就是我的xml文件现在看起来像但它不起作用,它只是将左边的两个图像按钮放在一起.我也试过没有额外的LinearLayouts但没有运气.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
  android:gravity="fill_horizontal"
  android:background="@drawable/list_header_background">
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:orientation="horizontal"
      android:gravity="left"
      android:background="@drawable/list_header_background">
        <ImageButton
            android:id="@+id/refreshBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="4dp"
            android:src="@drawable/ic_refresh"
            android:background="@drawable/list_header_background"
            />
    </LinearLayout>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:orientation="horizontal"
      android:gravity="right"
      android:background="@drawable/list_header_background">
        <ImageButton
            android:id="@+id/battleBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="4dp"
            android:src="@drawable/ic_battle"
            android:background="@drawable/list_header_background"
            />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

iCa*_*arp 5

正如kabuko所写,RelativeLayout宽度等于父宽度.当我们在其中有一个子视图时RelativeLayout,我们可以使用该android:layout_alignParentXXXXXX="true"参数来相应地将它(子)与父对齐.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="horizontal"
  android:background="@drawable/list_header_background">
  <ImageButton
      android:id="@+id/refreshBtn"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="4dp"
      android:src="@drawable/ic_refresh"
      android:layout_alignParentLeft="true"
      android:background="@drawable/list_header_background"
  />
  <ImageButton
      android:id="@+id/battleBtn"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="4dp"
      android:src="@drawable/ic_battle"
      android:layout_alignParentRight="true"
      android:background="@drawable/list_header_background"
   />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)