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

6

6

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.

Hoover answered 18/7, 2012 at 8:45 Comment(4)
What error shows Error Log?Axinomancy
here what is the use of second layout.......Cimbura
add one more view in Parent layout(may be blank or some usable if any) to remove the warning. In this code the horizontal layout has no use.Lewanna
Re Jin35: here is my error. dl.dropbox.com/u/78582670/error.png Re RajaReddy: I want to play some translation animation for the imageButton in linear layout. I want the buttons move from bottom to top. Do you have any good idea? Re Kamal:the horiontal layout is useful because i will add some view s into it in the future.Hoover
A
2

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>
Analysand answered 18/7, 2012 at 8:56 Comment(2)
Yes, I get it. In fact, why i write in this way is that I want to animate the image buttons to move from bottom to top. I don't want to hard code this animation. How can i do? And do you have the best way to do this?Hoover
You can do that with having single LinearLayout. lots of example are there. for example this post deal with animating button from bottom to topAnalysand
M
3

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.

Marienbad answered 8/4, 2013 at 17:26 Comment(0)
A
2

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>
Analysand answered 18/7, 2012 at 8:56 Comment(2)
Yes, I get it. In fact, why i write in this way is that I want to animate the image buttons to move from bottom to top. I don't want to hard code this animation. How can i do? And do you have the best way to do this?Hoover
You can do that with having single LinearLayout. lots of example are there. for example this post deal with animating button from bottom to topAnalysand
O
2

You can just add this to your parent LinearLayout:

tools:ignore="UselessParent"

By default, Android Studio shows these warnings if they are useless. tools:ignore="UselessParent" prevents this warning from showing up.

Overshoe answered 26/10, 2018 at 12:26 Comment(0)
S
0

You could try

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

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

However I never trust graphical layout in Eclipse.

Edit :

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

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
Shaffert answered 18/7, 2012 at 8:50 Comment(3)
Sorry. It works. But, i really want the nest layout is "Wrap_content".Hoover
Try to put wrap_content on the layout_height.Shaffert
When i add a background image into the second layout, like this android:background="@drawable/menu_bg2". Then can't work =[Hoover
P
0

You have opened 2 linearlayout, but there is only 1 linearlayout closing.

However, the second linearlayout has no sense since you are putting a box inside a box and then inserting items in the second one.

Phebephedra answered 18/7, 2012 at 8:58 Comment(6)
mmm, the closing </LinearLayout> was missing due to not well formed. but it was there, I fixed that. :)Analysand
because i want to animate the second box. i think nested layout can do that. so i go ahead. Do you have any idea?Hoover
Adil Soomro: What you mean the closing </LinearLayout> was missing?? In fact, my XML have two closing </LinearLayout>. What's wrong for me?Hoover
@KingWu: your closing tag was not visible in question, due to wrong formatting, I formatted it again. so now it is visible.Analysand
there's nothing wrong in the layout then. Can you please look for the error log? window->show view -> error logPhebephedra
i posted a link. You can go to see it.ThanksHoover
I
0

Perhaps help you :

android:layout_alignWithParentIfMissing ="true"
Imprecation answered 23/9, 2014 at 11:3 Comment(1)
I think it would be more helpful for the OP and further visitors, when you add some explanation to your intension.Desmoid

© 2022 - 2024 — McMap. All rights reserved.