我在scrollview中放了两个listview但是我有一个问题,当我把项目放在第一个listview中时,第二个listview将是可滚动的。我希望整个区域可以滚动而不是滚动视图,我怎么办?第一个scrollview是listViewEventiAggiunti第二个listViewEventi。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/activity_lista__eventi"
android:paddingBottom="@dimen/padBottom"
android:paddingLeft="@dimen/padLeft"
android:paddingRight="@dimen/padRight"
android:paddingTop="@dimen/padTop"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical">
<SearchView
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
android:id="@+id/cercaEvento"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="@+id/linearLayoutEventi">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Nome Evento"
android:textSize="22dip"
android:id="@+id/editText_nome_evento_composto"/>
<ListView
android:id="@+id/listViewEventiAggiunti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:id="@+id/separatore_liste"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@android:color/darker_gray"/>
<ListView
android:id="@+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/cercaEvento"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
我想要滚动整个区域,我不想在列表视图上滚动,当我将项目放在listview中时,区域增加并且我可以滚动整个区域吗?
答案 0 :(得分:1)
确定。由于您的最低SDK版本是16,因此您有2个解决方案可以解决您的问题。
首先使用这个库: https://github.com/PaoloRotolo/ExpandableHeightListView 这个库使你能够将ListViews扩展到全高,然后只有你的ScrollView可以滚动。
第二个解决方案是使用NestedScrollView而不是ScrollView,然后使用RecyclerView而不是ListView。那么你应该只为您的RecyclerView禁用nestedScrolling。
这两种解决方案都能满足您的愿望。
答案 1 :(得分:0)
您可以使用multiple type item for listview并简化布局,使其变得像这样
<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_lista__eventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/padBottom"
android:paddingLeft="@dimen/padLeft"
android:paddingRight="@dimen/padRight"
android:paddingTop="@dimen/padTop"
tools:context="com.example.fra87.eudroid.activity_class.Lista_Eventi"
>
<SearchView
android:id="@+id/cercaEvento"
android:layout_width="match_parent"
android:layout_height="50dp"
android:queryHint="Evento"
/>
<EditText
android:id="@+id/editText_nome_evento_composto"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/cercaEvento"
android:hint="Nome Evento"
android:textSize="22dip"
/>
<View
android:id="@+id/separatore_liste"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_below="@+id/editText_nome_evento_composto"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@android:color/darker_gray"
/>
<ListView
android:id="@+id/listViewEventi"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/separatore_liste"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
/>
</RelativeLayout>