Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayout or its LinearLayout parent is useless , Can i ignore the warning message?

I face the nest layout problems and throws some exceptions. The error is "This LinearLayout layout or its LinearLayout parent is useless ...". I know i can ignore it this warning by this setting.

Setting: Build Path->Configure Build Path.... Under Android Lint Preferences look for UselessParent and set it's severity to ignore or click Ignore All.

However, the Eclipse graphical layout cannot show anything and display an error message - "Index:0, Size 0, Exception details are logged in Window > Show View > Error Log".

How can i make the graphical layout shows the nest layout??

Here is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/menu_bg2"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item1"
            android:src="@drawable/alarm2x" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item2"
            android:src="@drawable/bank2x" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item3"
            android:src="@drawable/brief_case2x" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item4"
            android:src="@drawable/trolley2x" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/menu_item5"
            android:src="@drawable/calculator2x" />

    </LinearLayout>
</LinearLayout>

Thanks all.

like image 745
KingWu Avatar asked Jul 18 '12 08:07

KingWu


People also ask

What is the use of LinearLayout?

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.

What is RelativeLayout and LinearLayout?

Android Layout Types LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.


2 Answers

Because in the first LinearLayout, there is only 1 view in it, and it's a LinearLayout.

Here is the illustrated structure:

LinearLayout
    LinearLayout
        ImageButton
        ImageButton
        ImageButton
        ImageButton
        ImageButton
    // You should add another View or ViewGroup for the first LinearLayout

LinearLayout is a subclass of ViewGroup and is intended to group some View(s), at least 2 (CMIIW).

So, the warning was issued because it assumed your first LinearLayout didn't have anything to group or it didn't matter if you omitted it.

Sorry if my explanation in English is bad.

like image 131
Kiddo Avatar answered Nov 15 '22 09:11

Kiddo


You have two LinearLayout, one out of them is use-less till now. This warning suggests you to remove one of them. like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/LinearLayout1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/menu_bg2"
          android:orientation="vertical" >

     <!-- your other ImageView etc.-->
</LinearLayout>
like image 27
Adil Soomro Avatar answered Nov 15 '22 09:11

Adil Soomro