ListView下降到底部

时间:2016-11-02 12:30:59

标签: android android-layout listview android-fragments

我使用以下布局。基本上,它有自定义工具栏,导航抽屉,菜单,ListView(listView1)和adlay。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/header_bg"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/toolbar">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:layout_above="@+id/adlay"
            android:layout_margin="7dp"
            android:cacheColorHint="#00000000"
            android:divider="@android:color/transparent"
            android:dividerHeight="3dp">
        </ListView>
        <LinearLayout
            android:id="@+id/adlay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical" >
        </LinearLayout>
    </RelativeLayout>

    <ListView
        android:id="@+id/drawer_list"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="#eee"
        android:dividerHeight="1dp"
        android:background="#fff"
        android:layout_below="@+id/toolbar"
        >
    </ListView>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>

布局类似于以下顺序:

  1. 工具栏(带导航抽屉和菜单)
  2. ListView1的
  3. 薏苡
  4. listView1包含从外部XML文件加载的项目列表。

    问题是这个。如果listView1的项目不多,那么它会下降到底部,位于adlay上方,并且listView1上方有一个间隙,位于工具栏和listView1之间。显示如下:

    1. 工具栏(带导航抽屉和菜单)
    2. GAP! &lt; ---我不希望差距在这里!
    3. ListView1的
    4. 薏苡
    5. 这不是所希望的显示。

      理想情况下,我想要以下内容:

      1. 工具栏(带导航抽屉和菜单)
      2. ListView1的
      3. GAP应该在这里
      4. 薏苡
      5. 非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

我会根据您的要求编写一个布局文件。我希望它有用

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/white">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@android:color/black"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

        <android.support.v4.widget.DrawerLayout
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">

            <LinearLayout
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <ListView
                    android:id="@+id/listView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="start"
                    android:layout_weight="1"
                    android:cacheColorHint="#00000000"
                    android:divider="@android:color/transparent"
                    android:dividerHeight="3dp">
                </ListView>

                <LinearLayout
                    android:id="@+id/adlay"
                    android:layout_marginTop="10dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Your Adlay Layout"/>
                </LinearLayout>
            </LinearLayout>

            <ListView
                android:id="@+id/drawer_list"
                android:layout_width="240dp"
                android:layout_height="match_parent"
                android:layout_below="@+id/toolbar"
                android:layout_gravity="start"
                android:background="#fff"
                android:choiceMode="singleChoice"
                android:divider="#eee"
                android:dividerHeight="1dp">
            </ListView>
        </android.support.v4.widget.DrawerLayout>
    </RelativeLayout>