2016-11-02 40 views
0

我正在使用以下佈局。基本上,它有一個自定義工具欄,一個導航抽屜,一個菜單,一個ListView(listView1)和adlay。ListView下降到最低

<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. 薏仁

ListView1的由列表中從外部XML文件加載的項目。

問題是這樣的。如果listView1的項目不多,那麼它會下降到底部,坐在adlay之上,並且在工具欄和listView1之間的listView1上方有一個間隙。該顯示器是這樣的:

  1. 工具欄(與抽屜式導航和菜單)
  2. 差距! < ---我不希望差距在這裏!
  3. ListView1的
  4. 薏苡

這是不期望的顯示。

理想情況下,我想以下幾點:

  1. 工具欄(與抽屜式導航和菜單)
  2. ListView1的
  3. GAP應該在這裏
  4. 薏仁

任何幫助是多少讚賞。謝謝。

+0

你可以添加問題的屏幕截圖? – motis10

+0

感謝您的回答。但我已經解決了這個問題,保留了我的佈局中的所有內容,但只是將listView1的layout_height更改爲match_parent。 – Dopinder

回答

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> 
+0

感謝您的回答。但我已經解決了我的問題,保留了我的佈局,但只是將listView1的layout_height更改爲match_parent。 – Dopinder