Android XML属性比较多,全部记住不太现实,用的时候查文档是一条途径。如何迅速找到所需的XML属性?
Android包下面android.R.styleable 类包含下面所有组件相关的XML属性。
如:
public static final int[] LinearLayout_Layout
Since: API
Level
Attributes that can be used with a LinearLayout_Layout.
Includes the following attributes:
| Attribute | Description |
|---|---|
| Standard gravity constant that a child can supply to its parent. |
| Specifies the basic height of the view. |
| |
| Specifies the basic width of the view. |
值得一提的是:android:layout_gravity属性在TextView里面也能用。如设置TextView居中就需要这样:
android:layout_gravity="center_horizontal'.
可是TextView并没有继承android.widget.LinearLayout.LayoutParams。
这说明他们之间的属性是通用的。
本文介绍了Android中XML属性的使用方法,特别关注了android.R.styleable类中包含的各种组件相关的XML属性。文章列举了一些常用的属性,例如android:layout_gravity、android:layout_height等,并解释了这些属性如何在不同组件间通用。
699

被折叠的 条评论
为什么被折叠?



