Search code examples
androidlistviewandroid-linearlayout

Android 3 Layers Layout with listview


I'm trying to have a layout with 3 layers. I'm using 3 linearlayouts in which one of it is an listview, but my bottom Linearlayout does not appear on screen.

I need: On Top: Horizontal Linear Layout | On Center: Listview | On Bottom: Horizontal Linear Layout

I'm using this code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/BackGroundColor"
    android:orientation="vertical"
    android:scaleType="center" >

    <LinearLayout
        android:id="@+id/titleLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/filterButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/sectionTitle"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="(blank)" />

        <Button
            android:id="@+id/addCatButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/listview_style_list_selector" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottomLayout"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:background="@color/titleBgColor"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/optionsButton"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="left"
            android:layout_weight="0"
            android:background="@drawable/filtericon" />

        <TextView
            android:id="@+id/totalValue"
            style="@style/sectionTitle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="66,00€" />

        <Button
            android:id="@+id/savExpIncValues"
            android:layout_width="33dp"
            android:layout_height="33dp"
            android:layout_gravity="right"
            android:layout_weight="0"
            android:background="@drawable/effect_button_add_cat_click" />
    </LinearLayout>

</LinearLayout>

What's wrong? thanks


Solution

  • I've fixed the layout for you. Give it a try:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/BackGroundColor"
        android:orientation="vertical"
        android:scaleType="center" >
    
        <LinearLayout
            android:layout_alignParentTop="true"
            android:id="@+id/titleLayout"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:background="@color/titleBgColor"
            android:orientation="horizontal" >
    
            <ImageButton
                android:id="@+id/filterButton"
                android:layout_width="33dp"
                android:layout_height="33dp"
                android:layout_gravity="left"
                android:layout_weight="0"
                android:background="@drawable/filtericon" />
    
            <TextView
                android:id="@+id/sectionTitle"
                style="@style/sectionTitle"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="(blank)" />
    
            <Button
                android:id="@+id/addCatButton"
                android:layout_width="33dp"
                android:layout_height="33dp"
                android:layout_gravity="right"
                android:layout_weight="0"
                android:background="@drawable/effect_button_add_cat_click" />
        </LinearLayout>
    
        <ListView
            android:layout_above="@+id/bottomLayout"
            android:layout_below="@+id/titleLayout"
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/listview_style_list_selector"
             />
    
        <LinearLayout
            android:layout_alignParentBottom="true"
            android:id="@+id/bottomLayout"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:background="@color/titleBgColor"
            android:orientation="horizontal" >
    
            <ImageButton
                android:id="@+id/optionsButton"
                android:layout_width="33dp"
                android:layout_height="33dp"
                android:layout_gravity="left"
                android:layout_weight="0"
                android:background="@drawable/filtericon" />
    
            <TextView
                android:id="@+id/totalValue"
                style="@style/sectionTitle"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="66,00€" />
    
            <Button
                android:id="@+id/savExpIncValues"
                android:layout_width="33dp"
                android:layout_height="33dp"
                android:layout_gravity="right"
                android:layout_weight="0"
                android:background="@drawable/effect_button_add_cat_click" />
        </LinearLayout>
    
    </RelativeLayout>