android layout 0dp shows Suspicious size error

Viewed 755

this android xml code shows me error when i set android:layout_width="0dp" than its shows me error in linear layout

Error: Suspicious size: this will make the view invisible, probably intended for layout_height

I want to use an Edit Text view and a search Icon like this enter image description here

<LinearLayout
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="2.5"
        android:background="#fff"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="#fff"
        android:textSize="16dp" />


<ImageView
    android:layout_width="0dp"
    android:layout_height="42dp"
    android:layout_weight="0.5"
    android:src="@drawable/searchIcon" />

</LinearLayout>
3 Answers

Error: Suspicious size: this will make the view invisible, probably intended for layout_height

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.

For your problem, You should add addandroid:orientation="horizontal" instead of vertical.

 <LinearLayout
                    android:layout_width="80dp"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

FYI

All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding)

Read official guide line about Linear Layout

Change android:layout_width="80dp" to android:layout_width="match_parent" and android:orientation="vertical" to android:orientation="horizontal"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2.5"
            android:background="#fff"
            android:gravity="center"
            android:padding="10dp"
            android:textColor="#fff"
            android:textSize="16dp" />
    
    
        <ImageView
            android:layout_width="0dp"
            android:layout_height="42dp"
            android:layout_weight="0.5"
            android:src="@drawable/searchIcon" />
    
    </LinearLayout>

I resolve the error in this code

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="10dp"
    android:weightSum="3">

    <EditText
        android:id="@+id/textField"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="2.5"
        android:background="#fff"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="#000"
        android:textSize="16dp" />


    <ImageView
        android:id="@+id/search"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:src="@drawable/searchIcon" />


</LinearLayout>
Related