片段中的Android ListView未滚动
我的MainActivity片段中有一个listView,该片段由自定义ArrayAdapter呈现。问题是listview由于某种原因无法滚动 我的XML活动:片段中的Android ListView未滚动,android,listview,android-fragments,Android,Listview,Android Fragments,我的MainActivity片段中有一个listView,该片段由自定义ArrayAdapter呈现。问题是listview由于某种原因无法滚动 我的XML活动: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/too
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:design="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:screenOrientation="portrait"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#f1f1f1">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
design:menu="@menu/navigation" />
</LinearLayout>
我的XML片段:
<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"
android:screenOrientation="portrait"
tools:context=".Friends">
<Button
android:id="@+id/newfriendbutton"
android:layout_width="0dp"
android:layout_height="66dp"
android:text="@string/new_friend"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView6"
android:layout_width="395dp"
android:layout_height="wrap_content"
android:text="@string/instruct"
android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@+id/newfriendbutton"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="8dp" />
<ListView
android:id="@+id/friendListView"
android:layout_width="match_parent"
android:layout_height="592dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6"
tools:ignore="MissingConstraints"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1" />
</android.support.constraint.ConstraintLayout>
您确定ListView已满吗?只有当视图中的选项超过给定约束所能容纳的选项时,它才允许您滚动。在这种情况下,最好使用RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
android:screenOrientation="portrait"
tools:context=".Friends">
<Button
android:id="@+id/newfriendbutton"
android:layout_height="66dp"
android:text="@string/new_friend"
android:layout_width="match_parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/instruct"
android:textAlignment="center"
android:layout_centerHorizontal="true"
android:layout_below="@+id/newfriendbutton"/>
<ListView
android:id="@+id/friendListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView6"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"/>
</RelativeLayout>
我认为你应该尝试修正你的布局,布局高度=592dp看起来不正确不,这不是问题你应该真正使用权重,而不是固定大小,尽管列表确实没有满。