简体   繁体   English

我如何在Android中以单一布局设计ExpendableListView,RecylerView(GridView)

[英]How can i design expendablelistview, recylerview(gridview) in single layout in Android

Previously am designed expandablelistview and recyclerview inside ScrollView but i saw in stack overflow they said this is not good idea,never put a scrollable view inside another scrollable view.Then how can i design this. 以前是在ScrollView中设计的expandablelistview和recyclerview,但是我在堆栈溢出中看到他们说这不是个好主意,切勿将可滚动视图放在另一个可滚动视图中。然后我如何设计它。 This is my previous code: 这是我以前的代码:

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

Please tell me any one. 请告诉我任何一个。

Calculate height of Expandablelistview and RecyclerView programatically and Remove Scrollview 以编程方式计算ExpandablelistviewRecyclerView高度并删除Scrollview

here in below is class that caluclate height of expandable listview 下面是计算可扩展列表视图高度的类

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;
    }
 }

set height of expandalbelistview in oncreate activity 在oncreate活动中设置expandalbelistview的高度

   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)));
        }
    });

删除滚动视图并为线性布局添加权重,根据布局使用权重用于回收视图和列表视图,否则请使用动态高度代码来管理屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我怎样才能从 recylerview 获得单一价值 - how can i get single value from recylerview 如何在android的gridview中替换单个图像? - How can i replace single image in gridview in android? 如何使用 SQliteOpenHelper 存储 RecylerView - How Can I store RecylerView With Use SQliteOpenHelper 如何在Android布局中为所有GridView实现单个按钮 - How to implement a single button for all gridview in android layout 如何将多个布局添加到GridView? - How can I add multiple layout to GridView? Android - 如何为多个屏幕设置单一布局 - Android - How can I set single layout for multiple screens 如何在另一个Activity中从NumberPicker获取值以显示在expendablelistview子级的textView中 - How can I get value from NumberPicker in another Activity to show on my textView in expendablelistview child 如何在RecylerView中保存“ PDF”文件? - how can i save “ PDF ” file in RecylerView? 如何在RecylerView布局中修复按钮的位置? 我不希望按钮与RecyclerView中的图像一起滚动 - How can I fix the position of buttons in a RecylerView layout? I don't want the buttons to scroll along with the image in RecyclerView 我在列表项中有两个按钮,如何获取在Android的ExpendableListview中单击的按钮 - I have Two buttons in a list item, how to get which button is clicked in ExpendableListview in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM