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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With