简体   繁体   中英

Android complex button shape

How in Android the buttons with complex shape can be done?
For example, take a look at this joystick 在此处输入图片说明

  1. Each button should have several states (default, pressed, etc). It is simple to implement with regular buttons. How it can be done here?
  2. How is it possible to create custom clicking area shape (eg arch shape for button "Up") that will be a bit smaller than button shape?

Look at each button individually and use a layout (such as a FrameLayout or RelativeLayout ) to try and fit the pieces together. Start by making a ToggleButton and using a drawable background (`android:background="@drawable/button_background") to give it the look of one piece of the button. Do this and align all four buttons in the shape you'd like, then put place another layout behind them (with a background drawable) do complete the final piece, giving the buttons a container that makes it appear as one solid element for users.

I'm not entirely sure how you would work with the touch radius of each button... I suggest you look up other examples that work with 'odd' button shapes to hack together a working solution.

Android Custom Shape Button

I hope this points you in the right direction.

The real solution is to create own view to correctly handle such type of shapes. Custom views discussed here: https://developer.android.com/training/custom-views/index.html - you can also find some other sources on the net.

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