2010-10-22 99 views
1

在我的屏幕上我有一个列表视图和一个按钮。我的清单有8项。如果这两个项目不适合,我希望我的屏幕滚动。我不希望我的列表滚动,但包含列表&按钮的完整布局。如果我使用下面的布局,它只显示列表中的项目,我必须在列表中滚动才能进入下一个项目。滚动视图内的列表

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" > 
<LinearLayout 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <ListView android:id="@android:id/list" 
      android:layout_height="wrap_content" android:layout_width="fill_parent" 
      android:background="@drawable/round_background" /> 

     <Button android:text="Search" android:id="@+id/carSearchButton" 
      android:layout_gravity="center_horizontal" android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
</LinearLayout> 
</ScrollView> 
+0

你可以试试这个代码[non-scrollable-listview-inside-scrollview](http://stackoverflow.com/questions/18813296/non-scrollable-listview-inside-scrollview/24629341#24629341) – 2014-08-20 12:28:27

回答

1

镰刀那种回答我的问题,但我想多一个控制下面的列表也在另一个屏幕上我想要2列表。所以为了让滚动条与列表视图一起工作,我必须修复列表的高度。

2

你不能把一个ListView放在一个ScrollView中。 GridView的,或者任何View处理与ScrollView相同的轴上的滚动。这样框架就不知道哪个视图应该处理滚动事件。这种布局在编译时不会产生错误,但不能正常工作。

你应该在这里做什么:转储外部ScrollView,你不需要它。只使用ListView,并使用.addFooter()将按钮添加到ListView,这是最简单的方法。这样你的按钮就会显示为一个列表元素,但是你不必乱用自定义的适配器。

0

如果你的问题是与ListView不滚动ScrollView, 这里是解决这个问题的解决方案。

实现你自己的listview扩展ListView类并在其中实现下面的方法。

@Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: // Disallow ScrollView to intercept touch events. this.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: // Allow ScrollView to intercept touch events. this.getParent().requestDisallowInterceptTouchEvent(false); break; } super.onTouchEvent(ev); return true; }

让我知道这是否解决了您的问题?

+0

在这种情况下,如果我把它们都设置为false,它将在listView上滚动时禁用滚动屏幕 – HimanshuR 2013-10-29 10:44:40