Search code examples
androidxmlandroid-layoutlistviewandroid-linearlayout

Linear layout below the ListView, Some portions not visible?


I have a problem with LinearLayout which is below the listview. I tried to give the listview weight and layout above, set the layout_height to 0dp but nothing wotked.

Here is my XML code:

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

    <LinearLayout android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100"
        android:background="#00c4ff">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Application № - "
            android:layout_weight="50"/>
        <TextView
            android:id="@+id/number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="__"
            android:layout_weight="20" />
        <EditText
            android:id="@+id/date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="date"
            android:hint="dd/mm/yyyy"
            android:layout_weight="30"
            />
        </LinearLayout>

            <ListView
                android:id="@+id/lvMain"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </ListView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="bottom"
        android:id="@+id/ll">
        <Button
            android:id="@+id/plus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/comment"
            android:inputType="text"
            android:hint="Comment" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:gravity="bottom">
            <Button
                android:id="@+id/send"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Send" />
            <Button
                android:id="@+id/close"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Save and close"/>
        </LinearLayout>

    </LinearLayout>


</LinearLayout>

when ListView fills the screen, I cannot see the buttons below to it.


Solution

  • <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="100">
    
        <LinearLayout android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="100"
            android:background="#00c4ff">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Application № - "
                android:layout_weight="50"/>
            <TextView
                android:id="@+id/number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="__"
                android:layout_weight="20" />
            <EditText
                android:id="@+id/date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="date"
                android:hint="dd/mm/yyyy"
                android:layout_weight="30" />
        </LinearLayout>
    
        <ListView
            android:id="@+id/lvMain"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="90">
        </ListView>
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10"
            android:orientation="vertical"
            android:gravity="bottom"
            android:id="@+id/ll">
            <Button
                android:id="@+id/plus"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Add"/>
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/comment"
                android:inputType="text"
                android:hint="Comment" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:gravity="bottom">
                <Button
                    android:id="@+id/send"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Send" />
                <Button
                    android:id="@+id/close"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Save and close"/>
            </LinearLayout>
    
        </LinearLayout>
    
    
    </LinearLayout>