Place the view under the RecyclerView

I have a very simple question that for some reason cannot be implemented. I have a RecyclerView that populates only once when it creates an activity. I want to add another look to it.

If the RecyclerView does not fill the entire length of the screen (usually in portrait mode), the view should be located directly below it.

If the RecyclerView exceeds the length of the screen (usually in landscape mode), the view should still be located under it, but also should be fixed on the bottom of the screen.

Here it is.

I tried to arrange them in RelativeLayout, LinearLayout or CoordinatorLayout. With match_parent, wrap_content (with or without setAutoMeasureEnabled). With app: layout_anchor and app: layout_anchorGravity, but nothing works.

Appreciate any help.

This is an example of one of my attempts:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" /> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/features_list" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_anchor="@id/features_list" app:layout_anchorGravity="bottom" /> </android.support.design.widget.CoordinatorLayout> 
+5
source share
1 answer

Try the following: Note. I am using ScrollView since you said that the height of your RecyclerView may exceed the screen size.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- Required for the content to not exceed the screen --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:measureAllChildren="true"> <!-- Content --> </ScrollView> <!-- View that needs to be under the ScrollView or clipped to the button of the screen based on the ScrollView height --> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> </RelativeLayout> </LinearLayout> </LinearLayout> 
+1
source

Source: https://habr.com/ru/post/1275109/


All Articles