简体   繁体   中英

Android: custom shaped button

I'm looking the best way to create a group of four buttons.
在此处输入图像描述
Each button is an image. So, I think about just create a "big" square from four small images-buttons and then rotate them.
The question is: how to rotate layout in xml? Is it possible?

Is there any better way to create such group of buttons?


Thank you!

One way to do this is to create a single ImageButton, then use trigonometry to work out where the user has clicked on the circle, using data from an onClick() event and the centre of the button. This question may help: Get the co-ordinates of a touch event on Android

The ultimate answer is to use a pathshape button. Then it handles everything for you.

Create the paths with Path the shapes with Shape and the composite pathshape with Pathshape .

That way you can do it even in XML. And there's a variety of arc path methods. Check it out!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM