Android中的重叠视图

在Android中可能有重叠视图吗? 我想要在前面有一个透明PNG的ImageView和在后台的另一个视图。

编辑:

这是我现在所拥有的,问题是imageView中的图像不透明,应该透明的部分只是黑色。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/gallerylayout" > <Gallery android:id="@+id/overview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ImageView android:id="@+id/navigmaske" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/navigmask" /> </RelativeLayout> 

编辑:

我得到它的工作,这是从另一个程序员在团队的主题文件。 只是改变了这个

 <item name="android:background">#FF000000</item> 

对此

 <item name="android:background">#00000000</item> 

Android本身处理视图和可绘制(包括PNG图像)的透明性,所以您描述的场景(在Gallery前部分透明的ImageView )当然是可能的。

如果遇到问题,可能与布局或图片有关。 我已经复制了你所描述的布局,并成功实现了你之后的效果。 这是我使用的确切布局。

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gallerylayout" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Gallery android:id="@+id/overview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ImageView android:id="@+id/navigmaske" android:background="#0000" android:src="@drawable/navigmask" android:scaleType="fitXY" android:layout_alignTop="@id/overview" android:layout_alignBottom="@id/overview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout> 

请注意,我已经将父亲的RelativeLayout更改为fill_parent的高度和宽度, fill_parent通常是您为主Activity所需要的。 然后,我将ImageView的顶部和底部alignment到Gallery的顶部和底部,以确保它位于其前面。

我也明确地设置ImageView的背景是​​透明的。

至于图像绘制本身,如果你把PNG文件放在我看的地方,我可以在我的项目中使用它,看看它是否是负责任的。

另外,看看FrameLayout ,这是相机的图库应用程序如何实现缩放button覆盖。

如果要在布局中添加自定义叠加屏幕,则可以创build自定义线性布局并获取对绘图和按键事件的控制。 你可以我的教程 – 覆盖Android布局 – http://prasanta-paul.blogspot.com/2010/08/overlay-on-android-layout.html

可见的画廊改变可见性,这是​​你如何让画廊超过其他视图重叠。 Home示例应用程序有这个技术的一些很好的例子。

最简单的方法是在顶部图像视图的顶部放置-40dp的余量

是的,这是可能的。 然而,挑战是正确地进行布局。 最简单的方法是使用AbsoluteLayout,然后把两个图像放在你想要的地方。 除了稍后将其添加到布局之外,您不需要为透明png做任何特殊的操作。