2010-10-22 103 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