【发布时间】:2018-02-10 14:19:31
【问题描述】:
我正在开发一个小型学习工具项目,该项目有几个不同的视图,显示在不同的片段中。我想做的是当用户选择布局或视图(例如 TextView)时,会弹出一个对话框,显示其所有可用属性(例如 android:layout_width、android:layout_height、android:focusable 等)。我希望有一种方法可以以编程方式获取属性,而不是遍历每个布局/视图并手动在文件或类中键入属性。目前,我只有一个正在读取的 JSON 文件,但它变得非常乏味。不同的 API 版本也会出现问题。
只是为了了解我目前正在处理的内容,这是我的 JSON 文件:
{
"LayoutParams": [
"android:layout_height",
"android:layout_width"
],
"MarginLayoutParams": [
"android:layout_margin",
"android:layout_marginBottom",
"android:layout_marginEnd",
"android:layout_marginHorizontal",
"android:layout_marginLeft",
"android:layout_marginRight",
"android:layout_marginStart",
"android:layout_marginTop",
"android:layout_marginVertical"
],
"RelativeLayout": {
"inherited_properties": [
"MarginLayoutParams",
"LayoutParams"
],
"primary_properties": [{
"android:gravity": ["bottom", "center", "center_horizontal", "center_vertical", "clip_horizontal", "clip_vertical", "end", "fill", "fill_horizontal", "fill_vertical", "left", "right", "start", "top"],
"android:ignoreGravity": [""],
"android:layout_above": [],
"android:layout_alignBaseline": [],
"android:layout_alignBottom ": [],
"android:layout_alignEnd": [],
"android:layout_alignLeft": [],
"android:layout_alignParentBottom": [],
"android:layout_alignParentEnd": [],
"android:layout_alignParentLeft": [],
"android:layout_alignParentRight": [],
"android:layout_alignParentStart": [],
"android:layout_alignParentTop": [],
"android:layout_alignRight": [],
"android:layout_alignStart": [],
"android:layout_alignTop": [],
"android:layout_alignWithParentIfMissing": [],
"android:layout_below": [],
"android:layout_centerHorizontal": [],
"android:layout_centerInParent": [],
"android:layout_centerVertical": [],
"android:layout_toEndOf": [],
"android:layout_toLeftOf": [],
"android:layout_toRightOf": [],
"android:layout_toStartOf": []
}]
}
}
【问题讨论】:
标签: android android-layout android-view