【问题标题】:ScrollView show large space at bottomScrollView 在底部显示大空间
【发布时间】:2012-11-08 15:31:54
【问题描述】:

我在ScrollView 上添加了ButtonListViewButton 被添加到ScrollView 中的ListView 下面,但问题是它在按钮和ListView 之间显示了很大的空间。这是我的代码

ReservationDrinkListAdapter adp = new ReservationDrinkListAdapter(this,
            KukumberApplication.getInstance().getBottleService().menuItems);
        list.setAdapter(adp);
        Util.setListViewHeightBasedOnChildren(list);

以下方法用于在ScrollView中显示ListView

 public static void setListViewHeightBasedOnChildren(ListView listView)
   {
       ListAdapter listAdapter = listView.getAdapter(); 
       if (listAdapter == null) {
           // pre-condition
           return;
       }

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

我做错了什么?任何建议和示例代码将不胜感激。

【问题讨论】:

    标签: android listview scrollview


    【解决方案1】:

    在滚动视图中使用列表视图在技术上是可行的,但完全不建议这样做,这样做(扩展整个列表以便滚动视图容纳所有列表)违背了适配器视图的全部要点(性能),并且会导致你遇到过很多问题。

    您可以在以下答案中看到更多相关信息: How can I put a ListView into a ScrollView without it collapsing? How to add two listview in scrollview Why ListView cannot be used in a ScrollView? ListView inside ScrollView is not scrolling on Android

    还有更多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多