Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.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 此RelativeLayout布局或其LinearLayout父级无效_Android_Android Layout_Layout - Fatal编程技术网

Android 此RelativeLayout布局或其LinearLayout父级无效

Android 此RelativeLayout布局或其LinearLayout父级无效,android,android-layout,layout,Android,Android Layout,Layout,我正在开发安卓3.1。及以上应用 在一个活动中,我动态生成其布局。我正在使用formdetail.xml作为contentview: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.formdetail); Bundle extras = getIntent().getExtras

我正在开发安卓3.1。及以上应用

在一个活动中,我动态生成其布局。我正在使用formdetail.xml作为contentview:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.formdetail);

    Bundle extras = getIntent().getExtras();
    if (extras != null)
    {
        currentFormId = extras.getString("FormId");
    }
}
formdetail.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/detailLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/downloadFormsButton"
            android:enabled="false"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="@string/download_forms_button" />
        <TextView
            android:id="@+id/formErrorMsg"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textSize="16dp" >
        </TextView>
    </RelativeLayout>

</LinearLayout>

downloadFormsButton
formErrorMsg
必须始终处于表单中

但使用该xml,我得到了以下警告:

此RelativeLayout布局或其LinearLayout父级无用

我需要linearLayout以编程方式添加表格布局


如何解决此警告?

这只是来自
lint
的警告
Lint
不知道您以后会将视图附加到此布局,它会警告您添加了不必要的额外视图(增加布局深度)


你应该忽略这个警告(如果它真的困扰你,这里有一个链接来自
lint
)。

你要么忽略它,要么右键单击你的项目。单击
生成路径->配置生成路径…
。在
Android Lint Preferences
下查找
UselessParent
并将其严重性设置为忽略或单击
ignore All

编辑:


我收回最后一部分。我认为,
Ignore All
将清除所有Lint警告和错误。

Lint在其警告中是正确的,您的LinearLayout没有做任何有用的事情,因为它唯一的子项是RelativeLayout。拆下管路布置:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/detailLayout"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <Button android:id="@+id/downloadFormsButton" 
         android:enabled="false"
         android:layout_alignParentLeft="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" 
         android:layout_margin="10dp"
         android:text="@string/download_forms_button" />
 <TextView 
         android:id="@+id/formErrorMsg" 
         android:layout_alignParentRight="true"
         android:layout_alignParentBottom="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:padding="10dp"
         android:textSize="16dp" />
</RelativeLayout>

我的应用程序布局也有同样的问题

我不知道怎么做,也不知道这是不是正确的方式,但这得到解决后,设置背景属性的两个布局

现在没有任何警告,工作也很完美。希望它也能为你工作

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:background="@drawable/bg"
    android:layout_height="match_parent" >

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/bg2"
            android:layout_marginTop="10dp" >

            <ImageView
                android:id="@+id/img_BookImage"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:scaleType="fitXY"
                android:contentDescription="@string/India"
                android:src="@drawable/india" />
        </FrameLayout>

    </FrameLayout>


正如您在我的问题中所看到的,我需要一个线性布局来以编程方式添加表格布局。然后您可以将它们添加到您的RelativeLayout。。。不管怎样,我只是解释了Eclipse中Lint警告的原因Juno是这个菜单位于您的项目的属性->Android Lint首选项我认为您的父布局只包含一个子布局,您可以通过删除父线性布局来优化布局Layuti有两个linter认为是冗余的线性布局,但第一个布局保留一个固定在屏幕原点的背景图像,第二个布局将一些输入字段和文本作为一组水平和垂直居中放置。如果不使用这两种布局,我找不到一种方法来实现这一点,因此定义这两种布局的android:background属性消除了警告。