Android中的重叠视图

新手上路,请多包涵

Android中是否可以有重叠的视图?我想要一个 ImageView,前面有一个透明的 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>

编辑:

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

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

对此

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

原文由 Alexander Stolz 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 944
2 个回答

Android本机处理视图和可绘制对象(包括PNG图像)的透明度,因此您描述的场景(部分透明的 ImageViewGallery 前面)当然是可能的。

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

 <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 高度和宽度,这通常是您想要的主要活动。然后我将 ImageView Gallery 顶部和底部对齐,以确保它在它前面居中。

我还明确将 ImageView 的背景设置为透明。

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

原文由 Reto Meier 发布,翻译遵循 CC BY-SA 3.0 许可协议

另外,看看 FrameLayout ,这就是相机的画廊应用程序实现缩放按钮覆盖的方式。

原文由 reflog 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题