RadioGroup and TextView in a RelativeLayout - Radi

2019-06-12 02:23发布

问题:

This is what am trying to accomplish. A textView and beneath that a radioButton group in which radioButtons are added programmatically. Am able to get only the radioButton group displayed with radioButtons and not the textView. radioButton group is taking up all the space in layout and textView is invisible.

I have looked into numerous posts on stackoverflow.com on formatting and displaying in layout but still could not figure where am making the mistake.

Could you please help me with the issue?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

    <TextView
        android:id="@+id/sample"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp"
        android:background="@color/black"
        android:gravity="center"
        android:text="@string/sample"
        android:textColor="@color/white" />

    <RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical" >
    </RadioGroup>

</RelativeLayout>

回答1:

Change from RelativeLayout to LinearLayout. There is no 'orientation' property for RelativeLayout, as things are 'Relative' to each other.



回答2:

Adding XML that is working as expected for posterity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height=“wrap_content” >
</ListView>

<TextView
    android:id="@+id/sample"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:layout_marginBottom="20dp"
    android:layout_marginTop="20dp"
    android:background="@color/black"
    android:gravity="center"
    android:text="@string/sample"
    android:textColor="@color/white" />

<RadioGroup
    android:id="@+id/radio_group"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:layout_below="@+id/sample”
    android:orientation="vertical" >
</RadioGroup>

</RelativeLayout>