Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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 &引用;此RadioGroup布局或其相对的Yout父级可能是无用的”;_Android_Xml_Android Layout_Adt - Fatal编程技术网

Android &引用;此RadioGroup布局或其相对的Yout父级可能是无用的”;

Android &引用;此RadioGroup布局或其相对的Yout父级可能是无用的”;,android,xml,android-layout,adt,Android,Xml,Android Layout,Adt,我有一个内部带有RadioGroup的RelativeLayout视图。我正在尝试将RadioGroup嵌入RelativeLayout。因此,我要添加元素到我的布局。我的密码在这里 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_paren

我有一个内部带有RadioGroup的RelativeLayout视图。我正在尝试将RadioGroup嵌入RelativeLayout。因此,我要添加元素到我的布局。我的密码在这里

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<RadioGroup
    android:id="@+id/rg1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
>
    <RadioButton 
        android:id="@+id/r1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example1"
        android:checked="true"
    />

    <RadioButton 
        android:id="@+id/r2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example2"    
        android:checked="true"
    />
</RadioGroup>

如何解决此警告?

通常,当布局中只有一个元素时,会显示此警告

例如,内部只有一个LinearLayour的LinearLayour(最后一个可能有多个视图)将是无用的,因为它不满足任何布局目的(布局的目的是分发视图)


在您的特定情况下,您可以去掉外部的
相对性yout

是的,您是对的,这只是一个减少视图层次结构的警告

如果布局只有一个射线组,请使用以下代码

<RadioGroup

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rg1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
    <RadioButton 
        android:id="@+id/r1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example1"
        android:checked="true"
    />

    <RadioButton 
        android:id="@+id/r2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example2"    
        android:checked="true"
    />
</RadioGroup>

您的
RelativeLayout
中只有
RadioGroup
吗?如果是这样,那就没用了。此外,它只是一个警告,因此可以忽略它并继续运行。
<RadioGroup

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rg1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
    <RadioButton 
        android:id="@+id/r1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example1"
        android:checked="true"
    />

    <RadioButton 
        android:id="@+id/r2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Example2"    
        android:checked="true"
    />
</RadioGroup>