【问题标题】:RecyclerView under Swipe refresh layout is not showing in nested scroll view滑动刷新布局下的 RecyclerView 未在嵌套滚动视图中显示
【发布时间】:2019-06-20 14:34:08
【问题描述】:

我在滚动视图下的活动中有视图寻呼机和recyclerview。我在刷卡刷新布局下使用recyclerview。我的问题是当我在没有刷卡刷新布局的情况下使用recyclerview 时,它会显示在布局中,如果我将它包裹在刷卡下刷新布局然后它不会显示在布局中。

下面是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
android:orientation="vertical"
android:id="@+id/linearHome"
android:paddingBottom="16dp"
android:layout_marginTop="10dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginBottom="50dp">

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progress2"
    android:layout_centerInParent="true"/>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:id="@+id/homeOffers"/>

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/indicator"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp"
        app:tabBackground="@drawable/tab_selector"/>

   <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/refresh">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycle"/>

   </android.support.v4.widget.SwipeRefreshLayout>

 </LinearLayout>

</android.support.v4.widget.NestedScrollView>

</RelativeLayout>

请告诉我如何实现所需的布局。任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/linearHome"
        android:paddingBottom="16dp"
        android:layout_marginTop="10dp"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:layout_marginBottom="50dp">
    
        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/progress2"
            android:layout_centerInParent="true"/>
    
        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true"
            android:scrollbars="none">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <androidx.viewpager.widget.ViewPager
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:id="@+id/homeOffers"/>
    
                <com.google.android.material.tabs.TabLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/indicator"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="0dp"
                    />
    
                <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:id="@+id/refresh">
    
                    <androidx.recyclerview.widget.RecyclerView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/recycle"/>
    
                </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    
            </LinearLayout>
    
        </androidx.core.widget.NestedScrollView>
    
    </RelativeLayout>
    

    输出

    【讨论】:

    • 它工作正常,但我怎样才能滚动查看寻呼机。
    • 如何将整个布局包裹在滚动视图中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多