Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 210
TKV Avatar asked Jan 18 '23 21:01

TKV


2 Answers

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.

like image 111
WarrenFaith Avatar answered Feb 02 '23 22:02

WarrenFaith


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.

like image 29
Yevgeny Simkin Avatar answered Feb 02 '23 20:02

Yevgeny Simkin