Android 如何设计滚动视图和底部导航
我正在尝试使ScrollView包含ListView(使用viewstub)和底部导航,我正在尝试下面的代码,但滚动视图中的图像位于ListView/viewstub的顶部,而不是底部,您能帮助我解决此问题吗?这是我的代码:Android 如何设计滚动视图和底部导航,android,scrollview,Android,Scrollview,我正在尝试使ScrollView包含ListView(使用viewstub)和底部导航,我正在尝试下面的代码,但滚动视图中的图像位于ListView/viewstub的顶部,而不是底部,您能帮助我解决此问题吗?这是我的代码: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:id="@+id/linear1">
<ViewStub
android:id="@+id/stublist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inflatedId="@+id/showlayout"
android:layout="@layout/list_view"/>
</LinearLayout>
<ScrollView
android:id="@+id/scroll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/nembelas" />
</LinearLayout>
</ScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
您与子列表和滚动视图的线性布局具有与父级匹配的高度(它将相互覆盖)。此外,您的BottomNavigationView必须放在ScrollView下,以防止覆盖内容。您必须使用app:layout\u constraintotop\u tobottoof
或app:layout\u constraintBottom\u tototopof
。您的线性布局
和滚动视图
都将其高度设置为匹配父项
。它们都将在其父对象的顶部对齐。
如果要在下面显示scrollview存根列表
,需要这样做:
。。。
...