RadioGroup and TextView in a RelativeLayout - RadioGroup is hiding TextView

依然范特西╮ 提交于 2019-12-08 12:03:59

问题


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>


来源:https://stackoverflow.com/questions/30941902/radiogroup-and-textview-in-a-relativelayout-radiogroup-is-hiding-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!