Manu13k
Manu13k

Reputation: 366

Positioning of elements inside a LinearLayout

I have a question.

Is it possible to have two elements, one over the other in a LinearLayout?

Here is my actual XML LinearLayout. Actually, I have a LinearLayout which contains a list of elements (RecyclerView), and a simple "Open" Button :

<LinearLayout
    android:id="@+id/linearbox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- Start RecyclerView -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal" />

    <!-- Include Open Button -->
    <include layout="@layout/open_button" />

</LinearLayout>

I would like to add a View over my list of elements, I already made the layout. I just want to include it now over my list :

<include layout="@layout/open_button" />

Thanks

Upvotes: 1

Views: 62

Answers (1)

Man
Man

Reputation: 2817

As suggested by Avijit Karmakar you can't do that with LinearLayout, You'll have to use FrameLayout,
since that is best suited for those kind of requirement where you want to have one view over other. just change your root layout to FrameLayout

<FrameLayout
            android:id="@+id/linearbox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

                <!-- Start RecyclerView -->
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_horizontal" />

            <!-- Include Open Button -->
            <include layout="@layout/open_button" />
        </FrameLayout>

Upvotes: 1

Related Questions