TKV
TKV

Reputation: 2663

android layout creation issue

Am new to android development. I had created one android app and for that following is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:background="@drawable/bg"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/grid_layout_1"
    android:layout_centerInParent="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <Button android:id="@+id/btnLogin" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:text="@string/login_btn_text"/>
    <Button android:id="@+id/btnRegister" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:text="@string/reg_btn_text"/>

</LinearLayout>
</RelativeLayout>

Am getting the following warning :

This LinearLayout layout or its RelativeLayout parent is possibly useless;
transfer the background attribute to the other view

Can anyone tell the reason for this warning and a solution to the issue.?

Upvotes: 4

Views: 9079

Answers (4)

Noa
Noa

Reputation: 31

I got this message when designing my first Android app. I typed everything exactly like it said in the book down to the "T" and double checked everything many times.

My guess it has something to do with the book possibly being out of date but it's only a year old.

I would think the person writing the book would know what they are doing. It's "The Complete Idiot's Guide to Android App Development" 2011.

I'm aware of the lint option but what is the reasoning for using this even though it's useless?

Upvotes: 0

Go to

Window -> Preferences -> Android -> Lint Error Checking

Scroll and find "UselessParent" option. Change the severity option to Ignore.

Upvotes: 1

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

The answer to your question, as I just discovered myself, is to disable the new Lint "help". I suppose it's helpful to someone just starting out in Android, but to anyone that knows what they're doing, it's just a nuisance. For example, your "useless" nested linear layout might very well be a button inside a padded layout that might be awaiting being filled by some other element, at run time (or a billion other, entirely valid things).

In your preferences, under android/lint, just disable the warnings and you won't see these warnings anymore.

Upvotes: 2

WarrenFaith
WarrenFaith

Reputation: 57672

There is no real usage to have just a LinearLayout inside a RelativeLayout. So one of them is useless as this is redundant.

edit

This warning is triggered, when a Layout has only one child that is also a Layout. In this case one of both can be removed without any problems. It is recommended to remove these redundant layouts as they reduce the overall performance of the UI.

Upvotes: 6

Related Questions