Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

android - This RelativeLayout layout or its LinearLayout parent is useless

I'm developing an Android 3.1. and above application.

On one activity I generate its layout dynamically. I'm using formdetail.xml as 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 and formErrorMsg must be always in form.

But using that xml I get this warning:

This RelativeLayout layout or its LinearLayout parent is useless

I need linearLayout to add TableLayouts programmatically.

How can I solve this warning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Lint is correct in it's warning, your LinearLayout isn't doing anything useful, since its only child is a RelativeLayout. Remove the LinearLayout:

<?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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...