简体   繁体   中英

How to overlap a view with another?

I would like to display a ViewPager that shall fill the whole screen over an other view, hidding it. This second view shall be set at the bottom of the screen and shall be displayed when the user perform a fling from bottom to top on the ViewPager ; it shall perform an animation that will move the ViewPager to the top until the second view is displayed.

The fact is I cannot overlap the second view, it is always displayed and never hidden by the ViewPager. Whatever the order I use to configure my layout in the xml (declare ViewPager first and then the second view, or the inverse) or whatever I use RelativeLayout or FrameLayout.

Here is the code I use :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/hlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/bg_shelf"
        android:orientation="horizontal" >
    </LinearLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

I followed the following post : overlapping views in Android and I was able to overlap my view with the following xml configuration :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/hlist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_gravity="center_vertical"
        android:background="@drawable/bg_shelf"
        android:orientation="horizontal" >
    </LinearLayout>


    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignBottom="@id/hlist"
        android:layout_alignLeft="@id/hlist"
        android:layout_alignRight="@id/hlist"/>

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM