我想显示一个 ViewPager,它应在另一个 View 上填充整个屏幕,并将其隐藏。 第二个 View 应设置在屏幕底部,当用户在 ViewPager 上执行从下到上的滑动时应显示;它将执行一个动画,将 ViewPager 移动到顶部,直到显示第二个 View 。
事实是我不能重叠第二个 View ,它始终显示并且从不被 ViewPager 隐藏。无论我在 xml 中使用什么顺序来配置我的布局(先声明 ViewPager,然后声明第二个 View ,或者相反)或者我使用 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>
最佳答案
我关注了以下帖子:overlapping views in Android并且我能够将我的 View 与以下 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>
关于android - 如何将一个 View 与另一个 View 重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9586647/