AbsoluteLayout 的替代方案
问题“什么是 AbsoluteLayout 的有用替代方案?”这似乎是一个经常被问到但从未得到真正答案的问题。我的情况如下:
我想定位圆圈(为了简单起见,我使用RadioButtons进行测试),以便圆圈之间的距离在所有可能的显示尺寸上成比例。
我还需要知道圆圈的位置以匹配 onTouchEvent。
这对于 AbsoluteLayout 来说似乎相当容易,因为我可以(在运行时)获取 defaultDisplay 的宽度和高度,因此我可以相对于显示指标在 AbsoluteLayout 中定位对象。
现在,出于明显的原因,我想避免使用 AbsoluteLayout,但relativelayout似乎不是一种替代方案,因为据我所知,人们只能说“将该对象放在另一个对象旁边”或下方或其他什么。如何解决这个问题?
the question "What is a usefull alternative to AbsoluteLayout?" seems to be a question which is often asked, but never really answered. My situation is as follows:
I want to position Circles (for the sake of simplicity i used RadioButtons for testing) so that the distances between the circles are proportional on all possible display sizes.
Also i need to know the position of the circles to match onTouchEvent.
This seems fairly easy with AbsoluteLayout since i can get (at runtime) the defaultDisplay's width and height and so i can position Objects in an AbsoluteLayout relative to the display metrics.
Now I want to avoid AbsoluteLayout for obvious reasons, but RelativeLayout doesn't seem to be an alternative since - as far as i know - one can only say "put that object right next to that other object" or below or whatever. How to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,实现目标的最佳方法是使用 Canvas并自己画一切。在画布中,您可以获取运行时的屏幕信息,并且可以完全控制要绘制的内容。
In my Opinion the best way to achieve your goal is to use the Canvas and draw everything yourself. In the Canvas you have the information of the screen at runtime and you have full control of the things to draw.
如果您只需要绘制自己的形状(并处理所有正常的触摸事件)并且不需要同一视图上的其他 UI Widget,那么请使用 Canvas。
如果您确实需要此视图上的小部件,那么您唯一的选择是
AbsoluteLayout
。If you only need to draw your own shapes (and handle all normal touch events) and do not need other UI Widgets on the same view, then use
Canvas
.If you do need Widgets on this view then your only option is
AbsoluteLayout
.