简体   繁体   English

当滚动视图子级具有权重时,Android如何在父滚动视图中使用列表视图子级

[英]Android how to use list view child in parent scroll view when scroll view child have weight

android how to use List view in Scroll view parent. android如何在滚动视图父级中使用列表视图。 mean when i used list view in scroll view than nothing work my list view mean not scrolling the list item. 意思是当我在滚动视图中使用列表视图而不起作用时,我的列表视图意味着不滚动列表项。 i want when the list view have multiple list item then scroll view scrolling is disable and the list view will scrolling.on my end the list view and scroll view scrolling both not working properly. 我想要列表视图有多个列表项时禁用滚动视图滚动,并且列表视图将滚动。在我的一端,列表视图和滚动视图滚动均无法正常工作。 and in scroll view child have also weight. 在滚动视图中,孩子也有体重。

The main problem of you idea it's that Android doesn't support it. 您认为主要的问题是Android不支持它。

You can use a scrollview but you need resize listview with some function like 您可以使用滚动视图,但需要使用一些功能调整列表视图的大小

public static void getListViewSize(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();
    if (myListAdapter == null) {
        //do nothing return null
        return;
    }
    //set listAdapter in loop for getting final size
    int totalHeight = 0;
    for (int size = 0; size < myListAdapter.getCount(); size++) {
        View listItem = myListAdapter.getView(size, null, myListView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    //setting listview item in adapter
    ViewGroup.LayoutParams params = myListView.getLayoutParams();
    params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
    myListView.setLayoutParams(params);
    // print height of adapter on log
    Log.i("height of listItem:", String.valueOf(totalHeight));
}

This should be work fine with 3 listviews too (I had test it with 1), but listviews won't be scrollable (full expanded), only scrollview. 这也应该可以在3个列表视图中正常工作(我已经用1个测试过),但是列表视图将不能滚动(完全展开),只能滚动显示。

It's a limit, if you scroll on listview you lose control on scrollview, so if all are scrollable on some display resolution your app won't work fine. 这是一个限制,如果您在列表视图上滚动,则会失去对滚动视图的控制,因此,如果所有内容都可以在某个显示分辨率下滚动,则您的应用将无法正常工作。

The best solution for me it's use 3 fragments to show 3 listviews 对我来说最好的解决方案是使用3个片段显示3个列表视图

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM