【发布时间】:2017-05-02 07:24:54
【问题描述】:
ListView 不在 LinearLayout 内滚动。然后我添加了一个 ScrollView 并放置了包含 ListView 的 LinearLayout。但是我的代码仍然无法正常工作。这是我的完整 xml 代码...
bottom_content_geofence_show.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/des_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
app:cardBackgroundColor="@color/cardview_dark_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="12dp"
android:paddingStart="20dp"
android:paddingTop="12dp">
<TextView
android:id="@+id/textView16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Type of Geofence is Polygon"
android:textAllCaps="true" />
<TextView
android:id="@+id/created_by_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Created By Anuradha"
android:textAllCaps="true" />
<TextView
android:id="@+id/created_on_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CReated On 4 April, 2017"
android:textAllCaps="true" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/enforce_detail_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingStart="20dp"
android:paddingTop="20dp"
app:cardBackgroundColor="@color/cardview_dark_background">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical">
<TextView
android:id="@+id/enforce_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Enforced Assets"
android:textAlignment="viewStart"
android:textAllCaps="true"
android:textColor="@color/colorPrimary"
android:textSize="14sp" />
<ListView
android:id="@+id/asset_list"
style="@style/Widget.AppCompat.ListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:divider="@color/White"
android:groupIndicator="@null"
android:overScrollMode="always"
android:smoothScrollbar="true" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
此布局将显示在 NestedScrollView 内
activity_show.xml
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/bottom_content_geofence_show" />
</android.support.v4.widget.NestedScrollView>
请告诉我可能的解决方案。提前致谢。
【问题讨论】:
-
如果您正在使用
NestedScrollView,请不要再使用ScrollView。 -
好的,我将删除 ScrollView。但是这两种情况对我来说都是一样的。 Listview 滚动在有/没有滚动视图的情况下不起作用
-
它有固定的高度,所以它只会显示那部分的数据。检查 listview 是否填充了您的数据?
-
@Piyush 我已经更新了我的代码.....删除了 ListView 的滚动视图和固定高度,并为包含 ListView 的 LinearLayout 添加了固定高度.....你可以查看它。但是列表视图仍然没有滚动。列表视图填充数据但不滚动。
-
我的建议是使用
RecylerView而不是ListView。
标签: android xml android-layout listview