Выравнивание группы Android Radio над кнопками в относительном расположении

Я не могу расположить свою радиогруппу над кнопкой. Он идет сзади кнопки в относительном расположении. То, что я хочу, это радиогруппа над кнопкой. Я добавил вывод кода. Что я хочу, так это вывести группу радио на 2 кнопки. Может ли кто-нибудь помочь мне с этой проблемой пользовательского интерфейса?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
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="match_parent"
android:layout_height="match_parent"
android:focusable="true"
tools:context=".MainActivity">

<Button
    android:id="@+id/buttonBelow"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_centerInParent="true"
    android:background="#f00"
    android:text="Button Below" />

<Button
    android:id="@+id/buttonAbove"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerInParent="true"
    android:background="#ff0"
    android:text="Button Above" />


<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="#00f">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Male" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female" />

</RadioGroup>


</RelativeLayout>

person Amit Mishra    schedule 28.12.2018    source источник
comment
Добавьте текущий скриншот приложения для визуализации.   -  person Letsintegreat    schedule 28.12.2018
comment
Было бы хорошо, если бы вы разместили изображение текущего вывода и ожидаемого результата.   -  person Rumit Patel    schedule 28.12.2018
comment
@Zlytherin текущий снимок экрана такой же, как и в приложении. Я хочу, чтобы обе кнопки возвращались к радиогруппе и радиогруппе впереди.   -  person Amit Mishra    schedule 28.12.2018
comment
@RumitPatel Я хочу, чтобы радиогруппа была впереди, а обе кнопки сзади   -  person Amit Mishra    schedule 28.12.2018
comment
@AmitMishra, проверь мой ответ.   -  person Rumit Patel    schedule 28.12.2018


Ответы (3)


Измените свой xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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="match_parent"
    android:layout_height="match_parent"
    android:focusable="true">


<FrameLayout android:id="@+id/lin" android:layout_width="match_parent" android:layout_height="wrap_content"
             android:orientation="vertical" android:layout_centerInParent="true" android:layout_marginTop="24dp">



    <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center">

        <Button
                android:id="@+id/buttonBelow"
                android:layout_width="300dp"
                android:layout_gravity="center"
                android:layout_height="300dp"
                android:background="#f00"
                android:text="Button Below"/>

        <Button
                android:id="@+id/buttonAbove"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_gravity="center"
                android:background="#ff0"
                android:text="Button Above"/>

    </FrameLayout>

    <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#00f">

        <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="Male"/>

        <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Female"/>

    </RadioGroup>


</FrameLayout>

</RelativeLayout>
person Piyush    schedule 28.12.2018
comment
хорошая попытка @Piyush, но результат нежелателен. Я хочу, чтобы радиогруппа находилась над кнопкой, что означает, что обе кнопки возвращаются к радиогруппе, а радиогруппа переходит к двум кнопкам. - person Amit Mishra; 28.12.2018
comment
@AmitMishra, вместо того, чтобы объяснять это каждый раз, опубликуйте изображение ожидаемого и текущего вывода. - person Letsintegreat; 28.12.2018

Из этого ответа нам нужно просто поднять RadioGroup на 1dp. Без других изменений.

Это связано с тем, что Кнопка имеет значение по умолчанию android:elevation="1dp"., поэтому для RadioGroup, нам нужно установить большую высоту.

<Button
    android:id="@+id/buttonBelow"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_centerInParent="true"
    android:background="#f00"
    android:text="Button Below" />

<Button
    android:id="@+id/buttonAbove"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_centerInParent="true"
    android:background="#ff0"
    android:text="Button Above" />


<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="#00f"
    android:elevation="2dp">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Male" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female" />

</RadioGroup>

person Rumit Patel    schedule 28.12.2018

Попробуй это

<RelativeLayout 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="match_parent"
android:layout_height="match_parent"
android:focusable="true"
tools:context=".MainActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/buttonBelow"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerInParent="true"
        android:background="#f00"
        android:text="Button Below" />

    <Button
        android:id="@+id/buttonAbove"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:background="#ff0"
        android:text="Button Above" />
</RelativeLayout>
<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="#00f">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Male" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Female" />
</RadioGroup>

person Android Geek    schedule 28.12.2018