在Android的互相重叠的视图 [英] Overlapping Views in Android

查看:168
本文介绍了在Android的互相重叠的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有重叠Android的意见?我想有一个ImageView的一个透明的PNG在前面,并在后台另一种看法。

编辑:

这是我目前所面对的问题是,在ImageView的图像不是透明的,那应该是透明的部分都只是黑色的。

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / gallerylayout
>
<画廊机器人:ID =@ + ID /概述
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    />

 < ImageView的机器人:ID =@ + ID / navigmaske
 机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:SRC =@可绘制/ navigmask
    />

< / RelativeLayout的>
 

编辑:

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

 <项目名称=机器人:背景>#FF000000< /项目>
 

 <项目名称=机器人:背景>#00000000< /项目>
 

解决方案

Android的处理跨意见和可绘(包括PNG图片)本身,所以你描述(场景透明部分透明的的ImageView 中的图库)当然是可能的。

如果您有任何问题,可能涉及到无论是布局或图像。我复制你描述的布局,成功实现你后的效果。下面是我使用的确切布局。

 < RelativeLayout的
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:ID =@ + ID / gallerylayout
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT>
  <画廊
    机器人:ID =@ + ID /概述
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
  />
  < ImageView的
    机器人:ID =@ + ID / navigmaske
    机器人:后台=#0000
    机器人:SRC =@可绘制/ navigmask
    机器人:scaleType =fitXY
    机器人:layout_alignTop =@ ID /概述
    机器人:layout_alignBottom =@ ID /概述
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
  />
< / RelativeLayout的>
 

请注意,我已经父 RelativeLayout的更改为 FILL_PARENT 的高度和宽度一般为你想要一个主要活动。然后,我已经对准顶部和的ImageView 的底部的的顶部和底部的画廊来确保它的中心在它的前面。

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

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

Is it possible to have overlapping views in Android? I would like to have an ImageView with a transparent png in the front and another view in the background.

edit:

This is what I have at the moment, the problem is that the image in the imageView is not transparent, the parts that should be transparent are just black.

<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>

edit:

I got it to work, it was a theme file from another programmer on the team. Just changed this

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

to this

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

解决方案

Android handles transparency across views and drawables (including PNG images) natively, so the scenario you describe (a partially transparent ImageView in front of a Gallery) is certainly possible.

If you're having problems it may be related to either the layout or your image. I've replicated the layout you describe and successfully achieved the effect you're after. Here's the exact layout I used.

<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>

Note that I've changed the parent RelativeLayout to a height and width of fill_parent as is generally what you want for a main Activity. Then I've aligned the top and bottom of the ImageView to the top and bottom of the Gallery to ensure it's centered in front of it.

I've also explicitly set the background of the ImageView to be transparent.

As for the image drawable itself, if you put the PNG file somewhere for me to look at I can use it in my project and see if it's responsible.

这篇关于在Android的互相重叠的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆