Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单选按钮不显示_Android_Android Radiobutton - Fatal编程技术网

Android 单选按钮不显示

Android 单选按钮不显示,android,android-radiobutton,Android,Android Radiobutton,我正在做“高级Android开发课程”的练习。此代码不显示单选按钮: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" an

我正在做“高级Android开发课程”的练习。此代码不显示单选按钮:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="@color/my_fragment_color"
   android:orientation="horizontal"
   tools:context=".SimpleFragment">

<TextView
    android:id="@+id/fragment_header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
    android:padding="10dp"
    android:text="@string/question_article"/>

<RadioGroup
    android:id="@+id/radio_group"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RadioButton
        android:id="@+id/radio_button_yes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:text="@string/yes"/>

    <RadioButton
        android:id="@+id/radio_button_no"
        android:layout_marginRight="8dp"
        android:text="@string/no"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</RadioGroup>


单选按钮
在我删除
TextView
时出现。
TextView
如何隐藏这些按钮?我也尝试过使用
marginEnd
或weight atributes,但这不是一个解决方案。

您的
文本视图
高度是
匹配您的父母
,这就是为什么您的
RadioButton
不可见的原因

尝试在
文本视图中设置
android:layout\u weight=“1”
,它会起作用

试试这个

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/my_fragment_color"
        android:orientation="horizontal"
        tools:context=".SimpleFragment">

        <TextView
            android:id="@+id/fragment_header"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:padding="10dp"
            android:text="@string/question_article"/>

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/radio_button_yes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="8dp"
                android:text="@string/yes"/>

            <RadioButton
                android:id="@+id/radio_button_no"
                android:layout_marginRight="8dp"
                android:text="@string/no"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <TextView
        android:id="@+id/fragment_header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="10dp"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:text="@string/question_article"/>

    <RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/radio_button_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:text="@string/yes"/>

        <RadioButton
            android:id="@+id/radio_button_no"
            android:layout_marginRight="8dp"
            android:text="@string/no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RadioGroup>




</LinearLayout>

试试这个

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/my_fragment_color"
        android:orientation="horizontal"
        tools:context=".SimpleFragment">

        <TextView
            android:id="@+id/fragment_header"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:padding="10dp"
            android:text="@string/question_article"/>

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/radio_button_yes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="8dp"
                android:text="@string/yes"/>

            <RadioButton
                android:id="@+id/radio_button_no"
                android:layout_marginRight="8dp"
                android:text="@string/no"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <TextView
        android:id="@+id/fragment_header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:padding="10dp"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:text="@string/question_article"/>

    <RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/radio_button_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:text="@string/yes"/>

        <RadioButton
            android:id="@+id/radio_button_no"
            android:layout_marginRight="8dp"
            android:text="@string/no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </RadioGroup>




</LinearLayout>

对文本视图的高度和宽度使用换行内容,如下所示


您的
线性布局是
方向=“水平”
但是您的第一个
文本视图使用
layout\u width=“match\u parent”
全幅显示,没有为任何其他视图留出空间


检查您的布局。我不确定您是否希望
TextView
垂直位于
单选按钮上方

TextView
的属性分配不正确

android:layout_width="match_parent"

改为分配
wrap\u内容
,它将起作用。

make
textview
width
wrap\u内容
。在示例中,按钮位于文本旁边,我怎样才能把它们移到左边?@Pochmunik没有得到你能解释更多吗?我想我应该改变TextView的宽度和高度来包装内容,而不是添加另一个属性。TextView占据了整个片段,我只是把match_parent改为包装内容。@Pochmunik如果你想在版面中添加更多视图,你需要根据你的要求设置权重