如何在一个已有的视图顶部覆盖图标图像 [英] How to overlay an icon image on top of an exisiting view
问题描述
这是一个问题的两个部分。
This is a two part question.
我有我希望把它分成区仓库的图像;其中每个字母重新presents在仓库存储(A,B,C,D,E&安培F)。如果用户选择存储B,那么,我想以编程方式叠加在被指定为B的图像。
I have an image of a warehouse that I would like to divide it into regions (A,B,C,D,E & F) where each letter represents a storage in the warehouse. If the user selects storage "B" then I would like to programmatically overlay an icon over the region on the images that is designated for "B".
问:
- 什么是将图像细分成将描述每个储藏室的区域的好办法?
- 如何以编程方式放置一个图标在正确的区域?
感谢您。
推荐答案
答1:你可以使用的FrameLayout;的FrameLayout为叠加在另一个上面的图的一般机制
Answer to 1: You can use Framelayout; FrameLayout is the general mechanism for overlaying a view on top of another.
下面是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
<View
android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
然后在你的Java code,可动态设置您的叠加层的透明度:
Then in your Java code you can dynamically set the transparency of your overlay:
View overlay = (View) findViewById(R.id.overlay);
int opacity = 200; // from 0 to 255
overlay.setBackgroundColor(opacity * 0x1000000); // black with a variable alpha
FrameLayout.LayoutParams params =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, 100);
params.gravity = Gravity.BOTTOM;
overlay.setLayoutParams(params);
overlay.invalidate(); // update the view
<一个href=\"http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android?rq=1\">See这里
问题2:在的FrameLayout,可以通过拖动它们设置你想要的地方顶部的图标::如此简单
Question 2: In framelayout, you can set the icons on top of where you want by dragging them:: So simple!
希望这有助于:: XD
Hope this helped:: XD
这篇关于如何在一个已有的视图顶部覆盖图标图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!