将文本和图像分组 + Android 中的圆边
我被要求在android中制作一个视图,将多个项目(例如复选框或文本视图)分组在垂直行中,由透明分隔线分隔,而背景具有一定的alpha级别并且边缘是圆形的。
我想到了两种解决方案,如果您有的话,我希望能得到一些关于好的\坏的或其他解决方案的反馈。
- 只需使用常规线性布局,但有一个单一样式 A,它使用 9 补丁作为背景,包括填充、边距以及我需要的任何内容,使其看起来像我想要的。然后,我创建另一种样式 A.up 和 A.down ,它们代表最上面和最下面的项目,它们将使用不同的带圆角的 9 路径。
- 继承线性布局,在onMeasure和layoutChildren中向所有子项添加它们之间的某种空间,我可以为其创建可以在样式中自定义的新属性。我可以覆盖dispatchDraw以在绘制之前为每个视图绘制背景,以便我可以绘制圆形边框,我唯一的要求是添加到此布局的每个视图都必须具有透明背景。
那么你觉得怎么样?
i was requested to make in android a view that groups several items like checkboxes or text views in vertical rows, separated by transparent dividers while the background is with a certain alpha level and the edges are round.
I thought of two solutions and i hope for some feedback on good\bad or other solutions if you got'em.
- just use regualr linear layout but have a single style A that uses a 9 patch as background, includes padding,margins and whatever i need to make it look like what i want. i then create another style A.up and A.down that represents the upper most and lower most items that will use a different 9-path with round corners.
- inherit from linear layout, in the onMeasure and layoutChildren add to all the children some kind of space between them, i can create new attribute for it that can be customized in a style. i can override the dispatchDraw to paint the background for each view before it draws so i can paint my round borders, my only demand will be that each View added to this layout will have to be with transparent background.
So what do you think ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终我决定使用带有自定义分隔线的列表。
它看起来不错,但是当涉及到具有按钮和可点击文本视图等状态的项目时,列表有一个非常讨厌的错误,
我不知道如何解决这个问题,我在开发人员邮件列表中看到了大量有关它的邮件,在这里,大多数人说不要将有状态对象放入列表中。
所以它对我来说不是解决方案。
我要尝试的下一步是扩展正常布局,在底部有一个栏,并使用带有可绘制圆角的常规线性布局。
Eventually i decided to use a List with customized divider.
It looks good, however a list got a very nasty bug when it comes down to items with states like buttons and clickable textViews,
I'm notsure how to resolve that one, i've seen numerous mails about it in the developres mailing list and here, most saying don't put statefull objects in a list.
So it mist not be the solution for me.
Nest thing i'll try is extending the normal layouts to have a bar in their bottom and use regualr linear layout with round corners drawable.