Android 如何在布局中居中放置中间子级,并将其设置为接近中间子级?

Android 如何在布局中居中放置中间子级,并将其设置为接近中间子级?,android,layout,android-linearlayout,gravity,layout-gravity,Android,Layout,Android Linearlayout,Gravity,Layout Gravity,我有一个带有3个子视图的水平线性布局 我想让中间的孩子水平居中,并让它的兄弟姐妹在两侧各打8分 这是干净的方式吗 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="end" android:orientation="horizontal"> <include a

我有一个带有3个子视图的水平线性布局

我想让中间的孩子水平居中,并让它的兄弟姐妹在两侧各打8分

这是干净的方式吗

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:orientation="horizontal">
  <include
      android:id="@+id/child1"
      layout="@layout/child1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal|end"
      android:maxLines="1" />
  <include
      android:id="@+id/child2"
      layout="@layout/child2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:layout_marginStart="@dimen/separator_horizontal_margin"
      android:layout_marginLeft="@dimen/separator_horizontal_margin"
      android:layout_marginEnd="@dimen/separator_horizontal_margin"
      android:layout_marginRight="@dimen/separator_horizontal_margin" />
  <include
      android:id="@+id/child3"
      layout="@layout/child3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal|start"
      android:maxLines="1" />
</LinearLayout>

改为用户相对论

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end">
    <include
        android:id="@+id/child1"
        layout="@layout/child1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toStartOf="@id/child2"
        android:layout_gravity="center_horizontal|end"
        android:maxLines="1" />
    <include
        android:id="@+id/child2"
        layout="@layout/child2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="@dimen/separator_horizontal_margin"
        android:layout_marginLeft="@dimen/separator_horizontal_margin"
        android:layout_marginEnd="@dimen/separator_horizontal_margin"
        android:layout_marginRight="@dimen/separator_horizontal_margin" />
    <include
        android:id="@+id/child3"
        layout="@layout/child3"
        android:layout_toEndOf="@+id/child2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|start"
        android:maxLines="1" />
</RelativeLayout>


不能在线性布局中完成吗?我所做的不会起作用?相对布局让你对ui有更多的控制