android - 为 child 定义自定义 ViewGroup 属性

标签 android android-layout android-custom-view android-custom-attributes

我正在寻找一种方法来为他们的 child 使用的 View 定义自定义属性。例如 layout_centerInParent 用于 RelativeLayouts 的子级或 layout_span 用于 TableLayouts 的子级。

最佳答案

以防万一其他人像我一样来到这里希望得到一个方向:

在子级中定义的布局参数在父级中使用。例如,layout_centerInParentRelativeLayout 父级用来根据其此属性的值定位子级。

在自定义 ViewGroup 中,您可以创建一个扩展 ViewGroup.LayoutParams 的内部类。然后您可以在子项中使用 XML 属性并使用 View#getLayoutParams() 在自定义布局中检索它们方法。

可以看看this question and its answer .

关于android - 为 child 定义自定义 ViewGroup 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060754/

相关文章:

android - Android 中的自定义形状按钮

android - 使用 LinearLayout.LayoutParams 时出现 ClassCastException

java - 如何识别类的实例的唯一性

android - 将系统应用程序替换为您自己在android上修改的应用程序

android - 如何处理 Android 着色书应用程序的图像?

安卓警告 : Grows due to localized text expansion

android - 如何设置 RecyclerView 的最大高度?

android - 回收站查看 : listen to padding click events

android - 如何读取android :layout_height from style resource in custom View

android - Simpletarget 已弃用 glide 吗?