小编kel*_*ose的帖子

如何在Android中制作彼此重叠的自定义形状按钮

我有6个单独的图像与透明背景.如何将所有这些图像组合在一起作为按钮,如:

在此输入图像描述

从我读到的,我想我必须使用框架布局,以便有重叠的按钮.

点击时我需要每种颜色都是一个单独的按钮.

更新:我做了一个演示并检查onclick方法中的透明然而当我点击红色和蓝色交叉点附近的红色区域时,由于重叠视图,它没有注册红色按钮是单击.请帮忙!

https://www.dropbox.com/s/fc98nnnfbrtdh82/Photo%20Apr%2016%2C%202%2002%2013.jpg?dl=0

public boolean onTouch(View v,MotionEvent event){

                                     int eventPadTouch = event.getAction();
                                     int iX = (int)event.getX();
                                     int iY = (int)event.getY();          
                                     switch (eventPadTouch) {

                                         case MotionEvent.ACTION_DOWN:

                                             if (iX>=0 & iY>=0 & iX<TheBitmap.getWidth() & iY<TheBitmap.getHeight()&TheBitmap.getPixel(iX,iY)!=0) {
                                                 if (TheBitmap.getPixel(iX,iY)!=0) {
                                                     Toast.makeText(getApplicationContext(),"clicked blue",Toast.LENGTH_LONG).show();

                                                 }
                                             }
                                             return true;
                                     }

                                     return false;
                                 }
                             }
Run Code Online (Sandbox Code Playgroud)

android button android-imagebutton

6
推荐指数
1
解决办法
1153
查看次数

标签 统计

android ×1

android-imagebutton ×1

button ×1