Pon*_*ing 5 android button touch android-layout
在我的Android应用程序中,我在地球上有三个不规则形状,如下所示:

所以我将整个图像放在布局中.Globe is just an image .There is no role of globe here.现在我想在全球各个不规则形状的图像上放置一个按钮.
按钮总是长方形但是I want to get touch event for irregular shape,not for rectangular area.那么如何在这三个不规则形状上放三个按钮或者有任何解决方案?这样每个按钮的不同事件可以在活动中处理?
我不知道如何完成这项任务.请指导我这个.
有什么建议或意见吗?
任何帮助将不胜感激.
从上面的答案中,我得到了提示,最后我得到了解决方案如下:
我所做的是:
在xml文件中使用RelativeLayout
使用ImageView,如下:
<ImageView
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/glob2"
android:layout_marginBottom="24dp"
android:layout_marginLeft="80.5dp"
android:contentDescription="@string/profile_picture_description"
android:src="@drawable/pick_matches_background" />
Run Code Online (Sandbox Code Playgroud)
这里我相应地设置边距(左/右/下/上)。
在活动中,
宣布
Bitmap btmp; and
ImageView img;
Run Code Online (Sandbox Code Playgroud)
在onCreate方法中,
// initialized image view
img = (ImageView) findViewById(R.id.btn1);
img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// call your method here
}
});
StateListDrawable sdCreateTrip = (StateListDrawable) img
.getDrawable();
btmp = ((BitmapDrawable) sdCreateTrip.getCurrent())
.getBitmap();
Run Code Online (Sandbox Code Playgroud)
您现在就可以出发了。
| 归档时间: |
|
| 查看次数: |
1366 次 |
| 最近记录: |