2016-01-06 48 views
0

設計expendablelistview,在單個佈局recylerview(GridView控件)以前我設計expandablelistview和recyclerview內滾動型,但我在堆棧溢出看到他們說這不是好主意,從來沒有把滾動視圖內的另一個滾動視圖。那我該如何設計呢? 這是我以前的代碼:我如何能在Android的

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

     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

     <ExpandableListView 
     android:id="@+id/secPage_explist" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:choiceMode="singleChoice" 
     android:groupIndicator="@null" 
     android:nestedScrollingEnabled="true" 
    /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/grid_recycler_template" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/oreser_item_seperator" 
    /> 

     </LinearLayout> 
    </ScrollView> 

請告訴我任何一個。的ExpandablelistviewRecyclerView編程和刪除

回答

0

計算高度滾動型

這裏下面是類caluclate擴張的ListView的高度expandalbelistview的

public class Calculate_Height { 

public static int calculateHeight_expandable(ExpandableListView list) { 

    int height = 0; 

    ExpandableListAdapter listAdapter = list.getExpandableListAdapter(); 
    if (listAdapter == null) { 
     // pre-condition 
     return 0; 
    } 

     for (int i = 0; i < listAdapter.getGroupCount(); i++) { 
      View groupItem = listAdapter.getGroupView(i, false, null, list); 
      groupItem.measure(
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
        MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
      height += groupItem.getMeasuredHeight(); 

      if (list.isGroupExpanded(i)) { 
       for (int j = 0; j <listAdapter.getChildrenCount(i); j++) { 
        View listItem = listAdapter.getChildView(i, j, false, null, 
          list); 
        listItem.measure(MeasureSpec.makeMeasureSpec(0, 
          MeasureSpec.UNSPECIFIED), MeasureSpec 
          .makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
        height += listItem.getMeasuredHeight(); 
       } 
      } 
     } 

     height += list.getDividerHeight() * (list.getCount() - 1); 
     Log.i("height", "" + height); 
     return height; 
    } 
} 

集高度的OnCreate活動

expandable_myitem.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { 
     @Override 
     public void onGroupExpand(int groupPosition) { 
      expandable_myitem.setLayoutParams(new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.WRAP_CONTENT, 
        Calculate_Height.calculateHeight_expandable(expandable_myitem))); 
     } 
    }); 

expandable_myitem.setOnGroupCollapseListener(new  ExpandableListView.OnGroupCollapseListener() { 
     @Override 
     public void onGroupCollapse(int groupPosition) { 
      expandable_myitem.setLayoutParams(new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.WRAP_CONTENT, 
         Calculate_Height.calculateHeight_expandable(expandable_myitem))); 
     } 
    }); 
+0

感謝您的回覆,我怎麼能計算GridLayoutManager和Expandablelistview編程 – Rgv

+0

我編輯我的答案。從那裏你可以以編程方式計算ExpandableListview的高度..以同樣的方式,你可以做GridLayoutManager ....如果你堅持任何地方,讓我知道。謝謝 –

+0

謝謝你的支持。它只在子項不可見的情況下工作。如果子元素可見,則摺疊。 – Rgv

0

刪除滾動型&增加重量的線性佈局使用重量爲回收視圖和ListView按您的佈局其他明智使用動態高度代碼管理屏幕。

+0

感謝您的回覆,我如何以編程方式計算GridLayoutManager和Expandablelistview – Rgv