在Android中重叠视图

Ale*_*olz 74 android view android-relativelayout

是否可以在Android中拥有重叠的视图?我想在前面有一个透明的png,在后台有另一个视图.

编辑:

这就是我现在所拥有的,问题是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>
Run Code Online (Sandbox Code Playgroud)

编辑:

我得到了它的工作,它是团队中另一个程序员的主题文件.刚改变了这个

<item name="android:background">#FF000000</item>
Run Code Online (Sandbox Code Playgroud)

对此

<item name="android:background">#00000000</item>
Run Code Online (Sandbox Code Playgroud)

Ret*_*ier 69

Android本地处理视图和绘图(包括PNG图像)的透明度,因此您描述的场景(在a ImageView前部分透明Gallery)当然是可能的.

如果您遇到问题,可能与布局或图像有关.我已经复制了你描述的布局并成功实现了你想要的效果.这是我使用的确切布局.

<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>
Run Code Online (Sandbox Code Playgroud)

请注意,我已将父级更改为高级RelativeLayout和宽度,fill_parent通常是主活动所需的高度和宽度.然后我将顶部和底部对齐ImageView到顶部和底部,Gallery以确保它在它前面居中.

我还明确地设置了ImageView透明的背景.

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

  • A-HA!我在使用LinearLayout.我将其更改为Relative,然后将ImageView放在最后.现在淡出"正常"......耶!感谢代码/提示.这让我想起了我的傻瓜. (3认同)
  • 嗨我使用相同的xml布局编码,但我的透明图像不显示.它只显示黑屏.我想在我的代码中添加任何内容. (2认同)

ref*_*log 9

另外,看一下FrameLayout,这就是Camera的Gallery应用程序如何实现Zoom按钮叠加.


小智 7

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