如何让一个activity的两个item分别在左右边缘对齐一行?

问题描述 投票:0回答:0

如何分别在左右两侧对齐 Android 活动中的 RadioGroup 和 ImageButton?我要在显示屏的顶部制作一行,以便在左侧有两个单选按钮,在右侧有一个图像按钮。 我试试这个:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="top"
android:orientation="vertical">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:weightSum="2"
    android:orientation="horizontal">
    <RadioGroup
        android:id="@+id/rgLearnRepeat"
        android:gravity="left"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/rbLearn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="24dp"
            android:checked="true"
            android:text="@string/rbLearn_text"
            android:textColorLink="#00BCD4" />

        <RadioButton
            android:id="@+id/rbRepeat"
            android:text="@string/rbRepeat_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="24dp" />
    </RadioGroup>

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="67dp"
        android:onClick="onStatClick"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_weight="1"
        app:srcCompat="@drawable/ic_learn" />
</LinearLayout>

但是所有元素都向左对齐。

android android-activity android-linearlayout
© www.soinside.com 2019 - 2024. All rights reserved.