linearlayout没有在recyclerview下面显示

问题描述

在我的版式中,我有产品列表的recyclerview。.以下,我在linearlayout中显示总价...但在滚动时,linearlayout不显示

我的代码的场景:

1->当我在recyclerview上有一项时-> linearlayout可以正常显示

2->当我在recyclerview上有更多项目时->在向下滚动linearlayout时看不到(线性布局未显示

第二场比赛需要帮助...预先感谢

下面是代码xml:-

materialThemeOverlay

更新的代码:-

<?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>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/relative"
    android:id="@+id/nest"
    android:scrollbars="vertical">
  <androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_below="@id/relative"
    android:layout_height="wrap_content"
    android:id="@+id/recyleview"/>
</ScrollView>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:id="@+id/linearlayoutorder"
    android:layout_below="@id/nest"
    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>

获取错误-:<?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"> <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: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> </androidx.core.widget.nestedScrollView> </RelativeLayout>

Caused by: android.view.InflateException: Binary XML file line #34: ScrollView can host only one direct child

需要帮助

解决方法

以下解决方案对我有用:-

<?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>
,

您尚未为LinearLayout添加weightSum和方位值。

Source

,

您可以使用NestedScrollView而不是ScrollView。然后将RecyclerView以及LinearLayout放在NestedScrollView中。并启用Main。应该为您工作。

Dev

在您的Java类中,您已设置了recyclerview Main

,

以这种方式使用ConstraintLayout,这是您需要的完整xml代码

for (const style of styles) { // styles is an array of urls
    const stylesheet = document.createElement('link');
    stylesheet.setAttribute('rel','stylesheet');
    stylesheet.setAttribute('href',style);
    stylesheet.setAttribute('type','text/css');
    stylesheet.onload = (event) => {
        for (
            let i = 0;
            i < event.currentTarget.sheet.cssRules.length;
            i++
        ) {
            if (event.currentTarget.sheet.cssRules[i].type == 5) { // type 5 is @font-face
                const split = style.split('/');
                const stylePath = split
                    .slice(0,split.length - 1)
                    .join('/');
                let cssText =
                    event.currentTarget.sheet.cssRules[i].cssText;
                cssText = cssText.replace(
                    // relative paths
                    /url\s*\(\s*[\'"]?(?!((\/)|((?:https?:)?\/\/)|(?:data\:?:)))([^\'"\)]+)[\'"]?\s*\)/g,`url("${stylePath}/$4")`
                );

                const st = document.createElement('style');
                st.appendChild(document.createTextNode(cssText));
                document
                    .getElementsByTagName('head')[0]
                    .appendChild(st);
            }
        }
    };
    this.root.appendChild(stylesheet);
}