Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position a view below a RecyclerView

I have a very simple question that for some reason im not being to able to implement. I have a RecyclerView which is being filled only once upon its activity creation. I want to add another view below it.

If the RecyclerView doesnt fill the entire screen length (usually in portrait mode) the view should be positioned directly below it.

If the RecyclerView exceeds the screen length (usually in landscape mode) the view should still be positioned below it but should also be docked to the screen bottom.

Thats it.

I've tried position 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 is working.

Appreciate any help.

This is an example of one of my tries:

<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>
like image 489
AsafK Avatar asked Nov 07 '22 11:11

AsafK


1 Answers

Try this: Note: I'm using a ScrollView since you said the height of your RecyclerView can 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>
like image 102
Eselfar Avatar answered Nov 14 '22 21:11

Eselfar