设置RelativeLayout子级以填充未使用的空间

int*_*_32 16 android android-layout android-relativelayout

我有这个布局:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/stat_brightness_off"
        android:layout_toLeftOf="@id/brightnessSeekBar" />

    <SeekBar
        android:id="@+id/brightnessSeekBar"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/brightnessSeekBar"
        android:src="@drawable/stat_brightness_on" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我需要SeekBar填充所有未使用的水平空间ImageView(它们大约是64*64像素).我该怎么办?

Luk*_*rog 33

使用下面提供的代码:

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/img1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:src="@drawable/stat_brightness_on" />

    <SeekBar
        android:id="@+id/brightnessSeekBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_toLeftOf="@id/img2"
        android:layout_toRightOf="@id/img1" />

    <ImageView
        android:id="@+id/img2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/stat_brightness_on" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

  • 特别是,诀窍是将中间元素设置为与右元素的左侧对齐,并在左侧元素的右侧. (10认同)