Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a layout_height of 0dip instead of wrap_content for better performance.....how to remove this warning

How to remove this warning?

Use a layout_height of 0dip instead of wrap_content for better performance

like image 363
Salman Amjad Avatar asked Jul 03 '12 04:07

Salman Amjad


Video Answer


1 Answers

Ok let me explain through an example,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Hello World!!" />

</LinearLayout>

In the above example I am using android:layout_weight="1" for TextView by which I am telling the layout that my TextView will take the full height as of parent layout(LinearLayout). So, in that case android:layout_height="wrap_content" is of no use as the TextView will have the full size as parent LinearLayout. So, in that case its better to add android:layout_height="0dp" to make TextView wrap itself to the height of parent Layout.

like image 104
Lalit Poptani Avatar answered Nov 03 '22 09:11

Lalit Poptani