如何将一个视图与另一个视图重叠?

3
我想展示一个ViewPager,它将覆盖在另一个视图上,并隐藏它。第二个视图应该设置在屏幕底部,在用户从下往上滑动ViewPager时显示;它应该执行一个动画,将ViewPager移动到顶部,直到第二个视图被显示。
事实是我无法覆盖第二个视图,它总是被显示并且从未被ViewPager隐藏。无论我如何使用xml配置我的布局(先声明ViewPager然后是第二个视图或者反过来),或者使用RelativeLayout或FrameLayout,都无法解决问题。
这是我使用的代码:
<?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>
1个回答

2
我遵循了以下帖子:Android中的重叠视图,并且我能够通过以下xml配置使我的视图重叠:
<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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接