Android linearlayout未显示在recyclerview下方
在我的布局中,我有产品列表的recyclerview..在下面,我在linearlayout中显示总价…但在滚动页面上,linearlayout没有显示 我的代码场景: 1-->当我在recyclerview-->linearlayout上有一个项目时,显示良好 2-->当我在recyclerview-->上有更多项目时,无法看到向下滚动的线性布局(线性布局未显示) 第二场需要帮助…提前谢谢 以下是xml代码:--Android linearlayout未显示在recyclerview下方,android,xml,android-layout,android-recyclerview,scrollview,Android,Xml,Android Layout,Android Recyclerview,Scrollview,在我的布局中,我有产品列表的recyclerview..在下面,我在linearlayout中显示总价…但在滚动页面上,linearlayout没有显示 我的代码场景: 1-->当我在recyclerview-->linearlayout上有一个项目时,显示良好 2-->当我在recyclerview-->上有更多项目时,无法看到向下滚动的线性布局(线性布局未显示) 第二场需要帮助…提前谢谢 以下是xml代码:-- 需要帮助您尚未添加权重和方向值用于线性布局 您可以使用嵌套的ScrollVi
需要帮助您尚未添加权重和方向值用于线性布局
您可以使用嵌套的ScrollView而不是ScrollView。并将RecyclerView和LinearLayout放在NestedScrollView中。并启用android:nestedScrollingEnabled=true。应该对你有用
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled=true>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android:id="@+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="@color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="@+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
在java类中,您的recyclerview集合
recyclerview.setNestedScrollingEnabled(true或false)代码>像这样使用ConstraintLayout,下面是您需要的完整xml代码
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbartable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
app:collapseIcon="@drawable/back" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android:id="@+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="@color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="@+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
以下解决方案适合我:-
<?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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relative">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapseIcon="@drawable/ic_arrow_back_black_24dp"
android:id="@+id/toolbartable"
android:background="@color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nest"
android:scrollbars="vertical"
android:layout_below="@id/relative">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:id="@+id/recyleview"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/linearlayoutorder"
android:layout_below="@id/recyleview"
android:orientation="horizontal"
android:weightSum="2"
android:background="@drawable/border"
android:backgroundTintMode="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:layout_gravity="center"
android:layout_weight="1"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/totalidcost"
android:layout_gravity="right|center"
android:textAlignment="textEnd"
tools:ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
没有,我做了更改..但不起作用。。。情况仍然相同您不必在scroll view中使用Recyclerview。删除scrollview后,好的。情况仍然相同…滚动Recyclerview后未显示我在Recyclerview中嵌套了scrolling false我得到错误==>原因:android.view.InflateException:二进制XML文件行#34:scrollview只能承载一个直接由以下原因导致的子项:java.lang.IllegalStateException:ScrollView只能承载一个直接子项只需在nestedScrollView中创建linearLayout或RelativeLayout作为视图的父项。那你应该没事了。我将用层次结构更新我的答案。但是如果删除该项,它仍然占用空间吗?
<NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled=true>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android:id="@+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="@color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="@+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</LinearLayout>
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbartable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
app:collapseIcon="@drawable/back" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyleview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/linearlayoutorder"
app:layout_constraintTop_toBottomOf="@id/relative" />
<LinearLayout
android:id="@+id/linearlayoutorder"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#000000"
android:backgroundTintMode="@color/colorPrimary"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="TOTAL" />
<TextView
android:id="@+id/totalidcost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_weight="1"
android:textAlignment="textEnd"
tools:ignore="RtlCompat" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?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:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relative">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:collapseIcon="@drawable/ic_arrow_back_black_24dp"
android:id="@+id/toolbartable"
android:background="@color/colorPrimaryDark">
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nest"
android:scrollbars="vertical"
android:layout_below="@id/relative">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="false"
android:id="@+id/recyleview"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/linearlayoutorder"
android:layout_below="@id/recyleview"
android:orientation="horizontal"
android:weightSum="2"
android:background="@drawable/border"
android:backgroundTintMode="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL"
android:layout_gravity="center"
android:layout_weight="1"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/totalidcost"
android:layout_gravity="right|center"
android:textAlignment="textEnd"
tools:ignore="RtlCompat"></TextView>
</LinearLayout>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>