【问题标题】:How to overlap a view with another?如何将视图与另一个视图重叠?
【发布时间】:2012-03-06 15:28:42
【问题描述】:

我想显示一个 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>

【问题讨论】:

    标签: android android-relativelayout android-framelayout


    【解决方案1】:

    我关注了以下帖子:overlapping views in 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 2021-08-29
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多