【发布时间】:2019-03-26 14:57:23
【问题描述】:
当我在滚动视图或嵌套滚动视图中放置相同的父级时,不显示 Recyler 视图项。 我的要求是将滚动视图添加到屏幕的一半,其中包括带有框架布局和滑动刷新布局的回收器视图。
我已经尝试过 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>
我需要显示相对布局内的图像,其余内容应可滚动到图像下方,包括 recylerview 内容。 现在如果我在相对布局之后放置滚动视图,回收器视图内容不会显示,没有滚动视图回收器视图列表带有滚动条。
【问题讨论】:
-
提供你想要实现的画面?
-
您可以尝试从
FrameLayout转换为RelativeLayout。我复制粘贴了您的布局,发现 FrameLayout 不适用于您的场景。我改成RelativeLayout好像没问题。 -
可能你错过了 android:fillViewPort="true" for
ScrollView. -
@RahulAgrawal 你是否在相对之后添加了滚动视图,因为即使我添加相对布局代替框架布局,然后在第一个相对布局回收器未显示后添加滚动视图。
-
@Piyush 不工作
标签: android android-recyclerview scrollview swiperefreshlayout