【问题标题】:Listview with Listview as an items, the inner listview is not fully visibleListview 以 Listview 作为项,内部的 listview 不完全可见
【发布时间】:2023-03-12 13:39:02
【问题描述】:

我正在尝试使用列表视图作为项目的列表视图,内部列表视图(列表视图项目)中只有第一行可见。

我的列表视图项 xml 是:

<?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="wrap_content"
    android:background="@drawable/main_bg" >
    <ListView
        android:id="@+id/numbers_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="@null"
        android:divider="@null" >
    </ListView>
</RelativeLayout>

【问题讨论】:

    标签: android android-listview


    【解决方案1】:

    您不能拥有scrollable view in other scrollable views。如果您将列表视图放在ScrollView 中,也会发生同样的情况。
    出于您的目的,为什么不实现多个视图项类型?示例herehere

    【讨论】:

    • 或者,使用ExpandableListView
    • 我不需要内部列表视图来滚动
    • 那你为什么要加呢?为什么不使用某种ViewViewGroup
    • @gunar 我最后使用了一个视图,每个视图大约 40 个
    【解决方案2】:

    在一个可滚动视图内另一个不会滚动.. 在您设置适配器并传递您的列表视图后调用此方法..

    private void setListViewHeight(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
    View listItem = listAdapter.getView(i, null, listView);
    listItem.measure(0, 0);
    totalHeight += listItem.getMeasuredHeight();
    }
    
    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight
    + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
    }
    

    http://kirukkupayal-mani.blogspot.in/2012/11/android-expandable-listview-inside.html

    【讨论】:

      猜你喜欢
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 2014-12-12
      • 1970-01-01
      相关资源
      最近更新 更多