将文本和图像分组 + Android 中的圆边

发布于 2024-09-27 03:20:28 字数 456 浏览 3 评论 0原文

我被要求在android中制作一个视图,将多个项目(例如复选框或文本视图)分组在垂直行中,由透明分隔线分隔,而背景具有一定的alpha级别并且边缘是圆形的。

我想到了两种解决方案,如果您有的话,我希望能得到一些关于好的\坏的或其他解决方案的反馈。

  1. 只需使用常规线性布局,但有一个单一样式 A,它使用 9 补丁作为背景,包括填充、边距以及我需要的任何内容,使其看起来像我想要的。然后,我创建另一种样式 A.up 和 A.down ,它们代表最上面和最下面的项目,它们将使用不同的带圆角的 9 路径。
  2. 继承线性布局,在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.

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下凄凉 2024-10-04 03:20:28

最终我决定使用带有自定义分隔线的列表。
它看起来不错,但是当涉及到具有按钮和可点击文本视图等状态的项目时,列表有一个非常讨厌的错误,

  1. 您无法获得该项目的焦点,也看不到 ornage 栏,
  2. 您似乎没有获得 evnets流向列表中视图的子级。

我不知道如何解决这个问题,我在开发人员邮件列表中看到了大量有关它的邮件,在这里,大多数人说不要将有状态对象放入列表中。
所以它对我来说不是解决方案。
我要尝试的下一步是扩展正常布局,在底部有一个栏,并使用带有可绘制圆角的常规线性布局。

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,

  1. you get no focus for the item and don't see the ornage bar
  2. you don't seem to get the evnets flowing to the children of the View in the list.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文