Java Listview直到最后一项才滚动 您好,我有问题滚动直到最后一个项目滚动中间停止,这是我的布局代码。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="fragment.Equivalent"> <ListView android:id="@+id/listView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:focusable="false"/> <TextView android:id="@+id/txt404" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Message that will be shown if the listview is empty" android:textSize="21dp" android:textStyle="bold" android:visibility="invisible" /> </RelativeLayout>
尝试使用滚动视图:Java Listview直到最后一项才滚动 您好,我有问题滚动直到最后一个项目滚动中间停止,这是我的布局代码。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="fragment.Equivalent"> <ListView android:id="@+id/listView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:focusable="false"/> <TextView android:id="@+id/txt404" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Message that will be shown if the listview is empty" android:textSize="21dp" android:textStyle="bold" android:visibility="invisible" /> </RelativeLayout>,java,android,Java,Android,尝试使用滚动视图: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="fragment.Eq
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fragment.Equivalent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:scrollbarStyle="insideOverlay"
style="@android:style/Widget.Holo.ScrollView">
<TableLayout
android:id="@+id/table_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
</ScrollView>
</RelativeLayout>
解决方案是将布局更改为约束布局并更改listview的大小
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fragment">
<ListView
android:id="@+id/listView"
android:layout_width="399dp"
android:layout_height="485dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="0dp"
android:focusable="false"
android:visibility="visible"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/txt404"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="21dp"
android:textStyle="bold"
android:visibility="invisible"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintVertical_bias="0.391" />
</android.support.constraint.ConstraintLayout>
检查列表视图的大小是否小于相对长度。如果是的话,问题可能不是滚动,而是你在屏幕上能看到多少实际列表。请尝试android:layout\u height=“match\u parent”
查看ListView
@Fatal您可以共享片段的代码吗?我得到一个异常java.lang.IllegalStateException:ScrollView只能承载一个直接子级
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="fragment">
<ListView
android:id="@+id/listView"
android:layout_width="399dp"
android:layout_height="485dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="0dp"
android:focusable="false"
android:visibility="visible"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/txt404"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="21dp"
android:textStyle="bold"
android:visibility="invisible"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintBottom_creator="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintVertical_bias="0.391" />
</android.support.constraint.ConstraintLayout>