2017-07-21 29 views
0

我正在開發一個基礎API11的Android應用程序。我想在所有其他組件的滾動視圖中添加列表視圖,但我知道這是不正確的。所以,當我添加新的單元格時,我使得列表視圖像擴展一樣是靜態的,但是當我添加滾動視圖時,列表視圖變得可滾動。請在下面找到Android ScrollView列表視圖,但禁用滾動

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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/parentLayout"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fillViewport="true"> 

     <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:id="@+id/parentLayout"> 

    <TextView 
     android:id="@+id/groupNameTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Group Name" 
     android:gravity="center" 
     android:textSize="30sp" 
     android:layout_marginTop="10dp"/> 

     <EditText 
      android:id="@+id/grpName" 
      android:layout_below="@id/groupNameTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Enter group name" 
      android:textAlignment="center" 
      android:gravity="center"/> 
     <TextView 
      android:id="@+id/grpDescriptionTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Group Description" 
      android:gravity="center" 
      android:textSize="30sp" 
      android:layout_marginTop="14dp" 
      android:layout_below="@+id/grpName" 
      android:layout_alignParentLeft="true" /> 

     <EditText 
      android:id="@+id/grpDescription" 
      android:layout_below="@id/grpDescriptionTextView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:hint="Enter description" 
      android:gravity="center"/> 

     <TextView 
      android:id="@+id/individualEA" 
      android:layout_below="@id/grpDescription" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Individual's Email addresses" 
      android:gravity="center" 
      android:textSize="30sp" 
      android:layout_marginTop="10dp"/> 
     <!--<LinearLayout--> 
      <!--android:layout_width="match_parent"--> 
      <!--android:layout_height="wrap_content"--> 
      <!--android:layout_below="@id/individualEA"--> 
      <!--android:orientation="horizontal">--> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:id="@+id/addEmailAddressButton" 
       android:layout_height="40dp" 
       android:layout_below="@id/individualEA" 
       android:src="@mipmap/add_button" 
       android:background="@color/whitecolor" /> 
     <!--</LinearLayout>--> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/addEmailAddressButton" 
     android:id="@+id/eaListView" /> 

     <LinearLayout 
      android:id="@+id/twoButtonsLayout" 
      android:layout_width="match_parent" 
      android:layout_below="@id/eaListView" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/updateButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/create_account_button_bg" 
       android:text="Update" 
       android:layout_below="@id/eaListView" 
       android:padding="7dp" 
       android:layout_weight="1" 
       android:layout_margin="7dp" 
       android:layout_marginTop="30dp" 
       android:textColor="@color/whitecolor" 
       android:textSize="40sp" /> 
      <Button 
       android:id="@+id/deleteButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/delete_account_button_bg" 
       android:text="Delete" 
       android:layout_below="@id/eaListView" 
       android:layout_margin="7dp" 
       android:padding="7dp" 
       android:layout_weight="1" 
       android:textColor="@color/whitecolor" 
       android:textSize="40sp" /> 

     </LinearLayout> 

    </RelativeLayout> 
    </ScrollView> 
</RelativeLayout> 

的XML下面的截圖是我需要,但屏幕不滾動和列表視圖靜態和擴大。這發生在我評論滾動視圖和相對佈局時。 enter image description here

爲了使其滾動的,我添加滾動視圖和相對佈局,但滾動視圖使得列表視圖滾動,並降低等示於下面的屏幕快照列表視圖的大小。 enter image description here

在橫向模式下,它通過使屏幕可滾動和列表視圖爲靜態的方式工作。

我的問題是如何使屏幕滾動與列表視圖靜態和擴大像縱向和橫向的第一個屏幕截圖? P:我想過使用回收器視圖和卡片視圖,但基礎API是舊的,因此我無法繼續使用它。

謝謝

+0

爲什麼你不試試ExpandableHeightListView –

+1

你有沒有試過NestedScrollView? https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html –

回答

0

使用Expandableheightlistview

搖籃

編譯 'com.github.paolorotolo:expandableheightlistview:1.0.0'

XML代碼

<com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView 
       android:id="@+id/driverlist" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:divider="@drawable/separator_gray1"> 
</com.github.paolorotolo.expandableheightlistview.ExpandableHeightListView> 

其他來源代碼與列表視圖相同寫一套適配器後,這條線

listview.setExpanded(true); 
0

不要用一個ListView或任何可以滾動混合滾動型。

只需使用Listview HeaderView或/和Footerview。