2017-03-05 79 views
0

我有一個活動,它承載了幾個片段。此活動佈局還包含頁腳。其中一個片段有一個ListView,它需要可滾動,因爲最後一個項目出現在活動佈局的頁腳後面。問題是我無法使其滾動。我這裏還有我的佈局:在android中的ListView滾動問題

活動:

<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"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <include 
      layout="@layout/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/fragment_container"> 
     </FrameLayout> 

    </LinearLayout> 

    <include 
     layout="@layout/footer_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"/> 

</RelativeLayout> 


<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_drawer" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="#384554" 
    app:menu="@menu/navigation_drawer_resources" 
    app:itemTextColor="@android:color/white" 
    app:itemIconTint="@android:color/white" 
    app:headerLayout="@layout/navigation_drawer_header" 
    app:theme="@style/MyNavigationDrawer"/> 

    </android.support.v4.widget.DrawerLayout> 

我的片段:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:orientation="vertical" 
android:id="@+id/fragment_activities_catalogue"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="70dp" 
    android:id="@+id/city_picture" 
    android:src="@drawable/city_header" 
    android:scaleType="fitStart"/> 

<Button 
    android:layout_width="250dp" 
    android:layout_height="35dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_marginTop="5dp" 
    android:background="@drawable/button" 
    android:textAllCaps="false" 
    android:textColor="@android:color/white"/> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1px" 
    android:layout_marginTop="5dp" 
    android:background="#c4c4c4"/> 

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/listview" 
    android:layout_marginTop="8dp" 
    android:scrollbars="vertical" 
    android:smoothScrollbar="true"> 

</ListView> 

</LinearLayout> 

回答

1

從問題我明白你的頁腳隱藏了列表視圖的最後一項....

對於這一點,你可以修改你的佈局像這樣

<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"> 

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

     <LinearLayout 
      android:layout_weight="0.85" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:orientation="vertical"> 

      <include 
       android:layout_weight="0.20" 
       layout="@layout/extra_tool" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" /> 

      <FrameLayout 
       android:layout_weight="0.80" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/fragment_container"> 
      </FrameLayout> 

     </LinearLayout> 

     <include 
      android:layout_weight="0.15" 
      layout="@layout/extra_tool" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"/> 

    </LinearLayout> 


    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_drawer" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="#384554" 
     app:itemTextColor="@android:color/white" 
     app:itemIconTint="@android:color/white" 
     /> 

</android.support.v4.widget.DrawerLayout> 
0

你的第一個LinearLayout中是 「match_parent」 這樣的頁腳是後面或之前。

給這個LinearLayout中的ID(」 ...的TopComponent ... 「),並把佈局屬性 」layout_below =「 ...的TopComponent ......」 頁腳包括。

你必須嘗試abit如何佈局正確,但RelativeLAyout父母給你所有你需要的東西,通過設計師視圖,你可以檢查,如何把屬性正確,因爲你可以看到直接發生了什麼。

玩佈局屬性的LinearLayout和頁腳

0

您正在使用DrawerLayout它通過默認接收所有的觸動,在
公共布爾onNavigationItemSelected(菜單項項){},  函數返回虛假而不是真實。
試試看,如果有效。