简体   繁体   English

Android复杂的按钮形状

[英]Android complex button shape

How in Android the buttons with complex shape can be done? 在Android中如何完成形状复杂的按钮?
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. 单独查看每个按钮,然后使用布局(例如FrameLayoutRelativeLayout )尝试将各个部分组合在一起。 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. 首先制作一个ToggleButton并使用可绘制背景(`android:background =“ @ drawable / button_background”)为按钮赋予外观。 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 Android自定义形状按钮

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. 自定义视图在这里讨论: https : //developer.android.com/training/custom-views/index.html-您还可以在网上找到其他来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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