Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating two custom buttons

Can some one please help me on creating custom buttons like below? Is it possible? Have searched a lot and was able to find only some things which again turn out to be rectangular/square shapes. But I want two buttons to be triangular and to be arranged on up on the other and clickable only on their particular occupied areas. Code snippets are appreciated.

enter image description here

like image 554
Apparatus Avatar asked Mar 16 '13 11:03

Apparatus


1 Answers

You can do that by extending View and subclassing its onTouchEvent method, like this

public class BottomLeftTriangleButton extends View {

    // Copy superclass contructors

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getX() / getWidth() < event.getY() / getHeight()) {
            return super.onTouchEvent(event);
        }
        return false;
    }

}

This way, your custom view only intercept clicks on the bottom left area, corresponding to your "button 2" area. You can make the other area clickable by changing the "<" sign to ">".

Then put your 2 views in the same FrameLayout, and you're done.

like image 110
minipif Avatar answered Oct 14 '22 14:10

minipif