1
这是一个两部分问题。如何在现有视图顶部叠加图标图像
我有一个仓库的图像,我想将其划分为区域(A,B,C,D,E & F),其中每个字母代表仓库中的存储。如果用户选择存储“B”,那么我想以编程方式将图标叠加在指定为“B”的图像上的区域上。
问:
- 什么是细分图像划分成多个区域,将描述每个储藏室的一个好办法吗?
- 如何以编程方式将图标放置在正确的区域上?
谢谢。
这是一个两部分问题。如何在现有视图顶部叠加图标图像
我有一个仓库的图像,我想将其划分为区域(A,B,C,D,E & F),其中每个字母代表仓库中的存储。如果用户选择存储“B”,那么我想以编程方式将图标叠加在指定为“B”的图像上的区域上。
问:
谢谢。
回答1:您可以使用Framelayout; FrameLayout是覆盖另一个视图的一般机制。
下面是一个例子:
<?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代码中,你可以动态地设置您的叠加层的透明度:
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
问题2:在FrameLayout里,你可以通过拖动它们将图标放在你想要的位置上::简单!
希望对您有所帮助:: XD