2017-05-09 36 views
0

我有一个ScrollView,其中包含一些元素,其余两个ListViews之间。每个ListView中的项目数量为有限,而我做的不是希望它们滚动。然而,我确实希望ScrollView本身是可滚动的,出于某种原因,它不是。什么是解决这个问题的好方法?ScrollView在包含ListViews时不可滚动

几乎在任何地方我读过,它说我不应该把ListView放在ScrollView里面,但是我需要一些看起来类似于这个布局的东西,而且实际上是函数(包括标题,如果相应的列表为空反之亦然) -

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/root" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@color/light_gray_real"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/white" 
    android:elevation="15dp"> 

    <EditText 
     android:id="@+id/etSearch" 
     android:layout_width="match_parent" 
     android:layout_height="45dp" 
     android:hint="Search values here" 
     android:textCursorDrawable="@null" 
     android:paddingStart="10dp" 
     android:background="@android:color/transparent"/> 

    <ImageButton 
     android:id="@+id/btnClear" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end|center" 
     android:layout_margin="5dp" 
     android:src="@drawable/places_ic_clear" 
     android:background="@android:color/transparent"/> 
</FrameLayout> 


<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:isScrollContainer="true"> 

     <TextView 
      android:id="@+id/tvTitle1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Title 1" 
      android:paddingStart="10dp" 
      android:paddingTop="2dp" 
      android:paddingBottom="2dp" 
      android:visibility="gone"/> 

     <ListView 
      android:id="@+id/listview1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/white"/> 

     <TextView 
      android:id="@+id/tvTitle2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Title 2" 
      android:paddingStart="10dp" 
      android:paddingTop="2dp" 
      android:paddingBottom="2dp" 
      android:visibility="gone"/> 

     <ListView 
      android:id="@+id/listview2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/white"/> 
    </LinearLayout> 
</ScrollView> 

+1

http://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view – Pavan

+0

使用RecyclerView,它支持嵌套滚动 –

+0

看到这篇文章http://www.londatiga.net/它/编程/ android/make-android-listview-gridview-expandable-inside-scrollview/ – Redman

回答

1

由于滚动视图和ListView时,不支持嵌套滚动你不能跟他们走。要么你可以有你的自定义滚动视图或

你可以去nestedscrollview而不是scrollview和Recyclerview而不是listview。

+0

真棒,这个工程!我切换到NestedScrollView + RecyclerViews。滚动本身有点尴尬,但这很容易解决 - http://stackoverflow.com/questions/37301724/recyclerview-inside-nested-scrollview-scroll-but-does-not-fast-scroll-like -norma – Cookienator

+0

要删除'有点尴尬',你可以设置recyclerview.setNestedScrollingeEnabled(false)。在每个小型回收站上。 – mnp343