当我将scrollview添加为线性布局的父级时,Recycler视图不可见,其中Recycler视图放置在框架布局和滑动刷新布局中

问题描述 投票:0回答:1

当我在滚动视图或嵌套滚动视图中放置相同的父项时,不会显示Recyler视图项。我的要求是将scrollview添加到屏幕的一半,其中包括带框架布局和刷卡刷新布局的recyclerview。

我尝试过scrollview和nestedscrollview,但它还没来。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/restaurant_list_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/img_cusine_1"
            android:layout_width="fill_parent"
            android:layout_height="150dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="2dp"
            android:layout_marginRight="0dp"
            android:scaleType="fitXY"
            android:src="@drawable/food_1" />

        <ImageView
            android:id="@+id/arrow_white"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignBottom="@id/img_cusine_1"
            android:layout_marginLeft="20dp"
            android:layout_marginBottom="30dp"
            android:src="@drawable/white_arrow" />

        <TextView
            android:id="@+id/detail_restaurant_name"
            android:layout_width="183dp"

            android:layout_height="27dp"
            android:layout_alignTop="@+id/arrow_white"
            android:layout_alignBottom="@id/img_cusine_1"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"

            android:layout_marginStart="20dp"
            android:layout_marginLeft="31dp"
            android:layout_marginTop="-2dp"
            android:layout_marginEnd="125dp"
            android:layout_marginRight="125dp"
            android:layout_marginBottom="30dp"
            android:layout_toEndOf="@+id/arrow_white"
            android:layout_toRightOf="@+id/arrow_white"
            android:text="Restaurant Name"
            android:textColor="@color/white"
            android:textStyle="bold" />
    </RelativeLayout>

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

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/detail_restaurant_name_sub"
                style="@style/RestuarantNames"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:text="Restuarant Name" />

            <TextView
                android:id="@+id/detail_restaurant_ratings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="10dp"
                android:layout_marginRight="10dp"
                android:background="@color/textGreen"
                android:text="3.6"
                android:textColor="@color/white"
                tools:ignore="RtlHardcoded" />
        </RelativeLayout>

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

            <TextView
                style="@style/UserLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="@string/detail_retaurant_list_ratings_header" />

            <ImageView
                android:layout_width="250dp"
                android:layout_height="30dp"
                android:layout_marginTop="2dp"
                android:src="@drawable/rating" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="5dp"
            android:background="@android:color/darker_gray" />

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

            <TextView
                style="@style/UserLocation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="@string/detail_retaurant_list_delivery_place_header" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/green_arrow"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:contentDescription="User Location"
                    android:src="@drawable/icon_user_location"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/user_address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="3dp"
                    android:layout_marginEnd="146dp"
                    android:layout_marginRight="146dp"
                    android:layout_marginBottom="-6dp"
                    android:text="Rajouri Garden"
                    android:textStyle="bold"
                    tools:ignore="HardcodedText" />

                <!--<TextView
                    android:layout_alignParentRight="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/user_address_change"
                    android:text="@string/user_change"
                    android:layout_marginRight="10dp"
                    style="@style/User_Green_Font" />-->
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@android:color/darker_gray" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Delivery in 33 minutes.Live tracking available"
                android:textColor="#FF7F50"
                android:textStyle="bold" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@android:color/darker_gray" />

            <Switch
                android:id="@+id/vegSwitch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="@string/dish_type_veg"
                android:textColor="@color/grey"
                android:textStyle="bold" />

            <TextView
                style="@style/HeaderRestuarantsRecommendations"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/dish_type_best_sellers" />

            <FrameLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent">

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

                    <android.support.v7.widget.RecyclerView

                        android:id="@+id/recycler_food_list"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scrollbars="vertical" />

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

                <com.andremion.counterfab.CounterFab
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentBottom="true"
                    android:layout_gravity="bottom|end"
                    android:src="@drawable/ic_shopping_cart_black_24dp"
                    app:backgroundTint="#3CB371"
                    tools:ignore="VectorDrawableCompat" />

            </FrameLayout>
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

我需要显示在relativelayout内部的图像,其余的内容应该在包括recylerview内容的图像下方滚动。现在如果我在相对布局后放置scrollview,recyler视图内容不会显示,没有scrollview recyler视图列表附带滚​​动条。

android android-recyclerview scrollview swiperefreshlayout
1个回答
0
投票
<LinearLayout 
    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"
    android:layout_margin="10dp"
    android:orientation="vertical">

<RelativeLayout
    android:id="@+id/restaurant_list_header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/img_cusine_1"
        android:layout_width="fill_parent"
        android:layout_height="150dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="2dp"
        android:layout_marginRight="0dp"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher_background" />

    <ImageView
        android:id="@+id/arrow_white"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/img_cusine_1"
        android:layout_marginLeft="20dp"
        android:layout_marginBottom="30dp"
        android:src="@android:drawable/arrow_down_float" />

    <TextView
        android:id="@+id/detail_restaurant_name"
        android:layout_width="183dp"
        android:layout_height="27dp"
        android:layout_alignTop="@+id/arrow_white"
        android:layout_alignBottom="@id/img_cusine_1"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"

        android:layout_marginStart="20dp"
        android:layout_marginLeft="31dp"
        android:layout_marginTop="-2dp"
        android:layout_marginEnd="125dp"
        android:layout_marginRight="125dp"
        android:layout_marginBottom="30dp"
        android:layout_toEndOf="@+id/arrow_white"
        android:layout_toRightOf="@+id/arrow_white"
        android:text="Restaurant Name"
        android:textColor="@android:color/white"
        android:textStyle="bold" />
</RelativeLayout>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <RelativeLayout
            android:layout_wienter code heredth="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/detail_restaurant_name_sub"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentLeft="true"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:text="Restuarant Name" />

            <TextView
                android:id="@+id/detail_restaurant_ratings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="10dp"
                android:layout_marginRight="10dp"
                android:background="@android:color/holo_green_dark"
                android:text="3.6"
                android:textColor="@android:color/white"
                tools:ignore="RtlHardcoded" />
        </RelativeLayout>

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="String text" />

            <ImageView
                android:layout_width="250dp"
                android:layout_height="30dp"
                android:layout_marginTop="2dp"
                android:src="@android:drawable/btn_radio" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginTop="5dp"
            android:background="@android:color/darker_gray" />

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="detail_retaurant_list_delivery_place_header" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/green_arrow"
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:contentDescription="User Location"
                    android:src="@android:drawable/btn_radio"
                    tools:ignore="HardcodedText" />

                <TextView
                    android:id="@+id/user_address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginTop="3dp"
                    android:layout_marginEnd="146dp"
                    android:layout_marginRight="146dp"
                    android:layout_marginBottom="-6dp"
                    android:text="Rajouri Garden"
                    android:textStyle="bold"
                    tools:ignore="HardcodedText" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@android:color/darker_gray" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:text="Delivery in 33 minutes.Live tracking available"
                android:textColor="#FF7F50"
                android:textStyle="bold" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@android:color/darker_gray" />

            <Switch
                android:id="@+id/vegSwitch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:text="dish_type_veg"
                android:textColor="@android:color/darker_gray"
                android:textStyle="bold" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="string/dish_type_best_sellers" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                    android:id="@+id/swipe_layout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/recycler_food_list"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />
                </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
                <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentBottom="true"
                    android:layout_gravity="bottom|end"
                    app:backgroundTint="#3CB371"
                    tools:ignore="VectorDrawableCompat" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
</androidx.core.widget.NestedScrollView>

我想这会奏效。我将FrameLayout更改为RelativeLayout,然后将android:fillViewport =“true”添加到Nestedscrollview。现在recyclerview似乎是可见的。您可以尝试相同的方式,让我知道它是否有效

© www.soinside.com 2019 - 2024. All rights reserved.