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

kel*_*ose 6 android button android-imagebutton

我有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)

小智 0

您始终可以用作RelativeLayout包装器,然后将未来的按钮添加为子按钮,并且可以将它们定位为重叠。

例如:

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
    *
    *
    *
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用对齐/边距/坐标来定位ImageViews (或s)。Button

希望能帮助到你。