【问题标题】:Android :RecyclerView doesn't scollAndroid:RecyclerView 不滚动
【发布时间】:2018-05-21 17:37:16
【问题描述】:

这是我的 XML 代码,它在 Android 5、6、7 及更高版本上运行良好。 我看到它没有在低于 5 的 Android 上滚动。 我不知道这个问题与 RecyclerView 或 Device Memory 的焦点有关

例如在荣耀 4C 上它不滚动,而其他一些手机也像在 android 4.2.2 上的华为。

应用程序或智能手机似乎没有崩溃,只是没有滚动。

这是我的布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:background="@color/white"
    tools:context="ir.example.app.Activity.BuyInternetActivity">

    <include layout="@layout/actionbar"/>

    <ScrollView
        android:id="@+id/parent_internet"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/_5sdp"
            android:layout_margin="@dimen/_10sdp">

            <ir.exapmle.app.Widgets.Txtview
                android:id="@+id/lbl_buychargecoe_1"
                android:layout_gravity="center"
                android:gravity="bottom|center"
                android:layout_weight="0.2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="شماره موبایل مورد نظر را وارد کنید:"
                android:textColor="@android:color/black"
                android:textSize="@dimen/_13sdp" />

            <LinearLayout
                android:layout_marginTop="@dimen/_3sdp"
                android:weightSum="1"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_marginRight="@dimen/_10sdp"
                    android:layout_marginLeft="@dimen/_10sdp"
                    android:gravity="top"
                    android:background="@drawable/edittext"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_40sdp">

                    <ImageView
                        android:id="@+id/img_contact_internet"
                        android:layout_marginStart="@dimen/_20sdp"
                        android:layout_gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_phonebook_selected"/>


                    <ir.exapmle.app.Widgets.Edtview
                        android:background="@android:color/transparent"
                        android:focusableInTouchMode="true"
                        android:layout_weight="0.8"
                        android:layout_width="0dp"
                        android:layout_height="@dimen/_35sdp"
                        android:layout_gravity="center"
                        android:layout_marginRight="10dp"
                        android:id="@+id/edt_buynet_phonenumber"
                        android:gravity="center"
                        android:paddingTop="5dp"
                        android:maxLength="24"
                        android:paddingBottom="5dp"
                        android:paddingEnd="5dp"
                        android:paddingStart="13dp"
                        android:hint="09 - - - - - - - - -"
                        android:inputType="number"
                        android:textSize="@dimen/_12sdp"/>
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_marginBottom="@dimen/_10sdp"
                android:weightSum="1"
                android:id="@+id/lyt_ownNumber"
                android:gravity="right"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <Switch
                    android:theme="@style/SwitchCompatTheme"
                    android:textColor="@color/colorKipo"
                    android:id="@+id/switch_internetOwnNumber"
                    android:layout_weight="0.1"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:layout_width="@dimen/_40sdp"
                    android:layout_height="@dimen/_30sdp" />
                <ir.exapmle.app.Widgets.Txtview
                    android:layout_weight="0.1"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:layout_marginRight="@dimen/_10sdp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="@dimen/_11sdp"
                    android:text="شماره خودم"/>
            </LinearLayout>

            <ir.exapmle.app.Widgets.Txtview
                android:id="@+id/txt_operator"
                android:layout_gravity="center"
                android:gravity="bottom|center"
                android:layout_weight="0.2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="اپراتور موردنظر را انتخاب کنید:"
                android:textColor="@android:color/black"
                android:textSize="@dimen/_13sdp"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"/>

            <LinearLayout
                android:weightSum="1"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/img_buycharge_code_mci"
                    android:padding="@dimen/_3sdp"
                    android:layout_weight="0.3"
                    android:layout_width="@dimen/_64sdp"
                    android:layout_height="@dimen/_64sdp"
                    android:src="@drawable/ic_pin_mci_unselected" />

                <ImageView
                    android:id="@+id/img_buycharge_code_irancel"
                    android:layout_weight="0.3"
                    android:padding="@dimen/_3sdp"
                    android:layout_width="@dimen/_64sdp"
                    android:layout_height="@dimen/_64sdp"
                    android:src="@drawable/ic_pin_irancell_unselected"/>


                <ImageView
                    android:id="@+id/img_buycharge_code_rightel"
                    android:layout_weight="0.3"
                    android:padding="@dimen/_3sdp"
                    android:layout_width="@dimen/_60sdp"
                    android:layout_height="@dimen/_64sdp"
                    android:src="@drawable/ic_pin_rightel_unselected"/>

            </LinearLayout>

            <LinearLayout
                android:visibility="gone"
                android:orientation="vertical"
                android:id="@+id/lyt_packages"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_marginTop="@dimen/_10sdp"
                    android:layout_marginBottom="@dimen/_10sdp"
                    android:gravity="top"
                    android:weightSum="1"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <RelativeLayout
                        android:layout_weight="0.5"
                        android:gravity="center"
                        android:weightSum="1"
                        android:background="@drawable/card_border"
                        android:orientation="horizontal"
                        android:layout_width="0dp"
                        android:layout_height="match_parent">
                        <Spinner
                            android:layout_margin="@dimen/_5sdp"
                            android:background="@drawable/spinner_border"
                            android:id="@+id/spin_terms"

                            android:layout_width="match_parent"
                            android:layout_height="@dimen/_30sdp">
                        </Spinner>
                        <ImageView
                            android:layout_width="@dimen/_24sdp"
                            android:layout_height="@dimen/_24sdp"
                            android:layout_alignEnd="@+id/spin_terms"
                            android:layout_centerVertical="true"
                            android:layout_marginEnd="12dp"
                            android:padding="@dimen/_5sdp"
                            android:src="@drawable/ic_arrow_down" />
                    </RelativeLayout>

                    <ir.exapmle.app.Widgets.Txtview
                        android:layout_weight="0.5"
                        android:gravity="center"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:textSize="@dimen/_10sdp"
                        android:text="مدت زمان بسته را انتخاب کنید :"/>

                </LinearLayout>


                <ir.exapmle.app.Widgets.Txtview
                    android:id="@+id/txt_selectedPackage"
                    android:gravity="center"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textColor="#000"
                    android:textSize="@dimen/_10sdp"
                    android:text="هنوز بسته ای را انتخاب نکرده اید"/>

                <LinearLayout
                    android:id="@+id/lyt_packageContents"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <LinearLayout
                        android:padding="@dimen/_5sdp"
                        android:weightSum="1"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ir.exapmle.app.Widgets.Txtview
                            android:gravity="center"
                            android:layout_weight="0.33"
                            android:layout_width="0dp"
                            android:textSize="@dimen/_11sdp"
                            android:layout_height="wrap_content"
                            android:text="مبلغ"/>

                        <ir.exapmle.app.Widgets.Txtview
                            android:gravity="center"
                            android:layout_marginLeft="@dimen/_4sdp"
                            android:layout_weight="0.34"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:textSize="@dimen/_11sdp"

                            android:text="توضیحات"/>

                        <ir.exapmle.app.Widgets.Txtview
                            android:layout_marginRight="@dimen/_5sdp"
                            android:gravity="center"
                            android:layout_weight="0.33"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:textSize="@dimen/_11sdp"

                            android:text="حجم"/>
                    </LinearLayout>
                    <LinearLayout
                        android:layout_marginLeft="@dimen/_15sdp"
                        android:layout_marginRight="@dimen/_15sdp"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="#ccc" />
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recycler_internets"
                        android:padding="@dimen/_5sdp"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/_110sdp">
                    </android.support.v7.widget.RecyclerView>
                </LinearLayout>
            </LinearLayout>



    </ScrollView>

</LinearLayout>

感谢您的帮助:)

【问题讨论】:

    标签: android scroll android-recyclerview


    【解决方案1】:

    只需在布局中使用 NestedScrollView 而不是 ScrollView

    <android.support.v4.widget.NestedScrollView
    android:id="@+id/parent_internet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    
    <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/_5sdp"
    android:layout_margin="@dimen/_10sdp">
    
    <ir.exapmle.app.Widgets.Txtview
    android:id="@+id/lbl_buychargecoe_1"
    android:layout_gravity="center"
    android:gravity="bottom|center"
    android:layout_weight="0.2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="شماره موبایل مورد نظر را وارد کنید:"
    android:textColor="@android:color/black"
    android:textSize="@dimen/_13sdp" />
    
    <ir.exapmle.app.Widgets.Txtview
    android:layout_marginRight="@dimen/_5sdp"
    android:gravity="center"
    android:layout_weight="0.33"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textSize="@dimen/_11sdp"
    
    android:text="حجم"/>
    </LinearLayout>
    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    <LinearLayout
    android:layout_marginLeft="@dimen/_15sdp"
    android:layout_marginRight="@dimen/_15sdp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ccc" />
    <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_internets"
    android:padding="@dimen/_5sdp"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_110sdp">
    </android.support.v7.widget.RecyclerView>
    </LinearLayout>
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      在您的 XML 文件中使用 NestedScrollView 而不是 ScrollView 并设置 recyclerView.setNestedScrollingEnabled(false);

      【讨论】:

      • 不再工作,我认为如果我使用 NestedScrollView 并忽略这一行代码:recyclerView.setNestedScrollingEnabled(false);它会工作
      【解决方案3】:
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout 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"
      android:orientation="vertical"
      aandroid:background="@color/white"
      tools:context="ir.example.app.Activity.BuyInternetActivity">
      
      <include layout="@layout/actionbar"/>
      
      <ScrollView
      android:id="@+id/parent_internet"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
      
      <LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="@dimen/_5sdp"
      android:layout_margin="@dimen/_10sdp">
      
      <ir.exapmle.app.Widgets.Txtview
      android:id="@+id/lbl_buychargecoe_1"
      android:layout_gravity="center"
      android:gravity="bottom|center"
      android:layout_weight="0.2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="شماره موبایل مورد نظر را وارد کنید:"
      android:textColor="@android:color/black"
      android:textSize="@dimen/_13sdp" />
      
      <ir.exapmle.app.Widgets.Txtview
      android:layout_marginRight="@dimen/_5sdp"
      android:gravity="center"
      android:layout_weight="0.33"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:textSize="@dimen/_11sdp"
      
      android:text="حجم"/>
      </LinearLayout>
      </LinearLayout>
      </ScrollView>
      <LinearLayout
      android:layout_marginLeft="@dimen/_15sdp"
      android:layout_marginRight="@dimen/_15sdp"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#ccc" />
      <android.support.v7.widget.RecyclerView
      android:id="@+id/recycler_internets"
      android:padding="@dimen/_5sdp"
      android:layout_width="match_parent"
      android:layout_height="@dimen/_110sdp">
      </android.support.v7.widget.RecyclerView>
      </LinearLayout>
      </LinearLayout>
      

      【讨论】:

      • 请说明它是如何回答问题的。
      猜你喜欢
      • 2016-10-26
      • 2021-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多