1、padding和margin
Margins create space on the outside of a view, which will separate the view from the surrounding views.
Padding creates space inside a view.
2、gravity和layout_gravity
The gravity attribute controls the default position of a view’s children inside that view.
By default, layout containers have gravity set to left. Most other views have their default gravity set to center.
layout_gravity specifies the posi-tion of a view to its parent.
3、LinearLayout的layout_weight
Child views specify how much space they will consume within the linear layout. They do this by setting a layout_weight. This parameter specifies the relative weight of one view versus the other views. By default, all views have a weight of 0. This means they will take up exactly as much space as they need to contain their content. Setting a weight higher than 0 will make a view expand to fill the remaining space in the layout. The relative value of the weight versus the weight of other views will determine how much space a particular view consumes.
a somewhat confusing aspect of using layout_weight is its relationship to the layout_height and layout_width attributes. the weight will generally override the height and width, but not always. if you plan to use the layout_weight attribute, set the corresponding height or width to 0dp. that way, the view size will be controlled by the weight and nothing else。
4、You cannot have a circular dependency in a relative layout. so, for example, you cannot set the width of the RelativeLayout to wrap_content and use alignParentTop on one of the child views. this will generate an error, and your R.java file will not be generated.
5、res目录下的图片会根据屏幕分辨率的不同而呈现不同的尺寸大小。可使用ldpi、mdpi、hdpi或xhdpi来创建针对不同屏幕分辨率的不同大小的图片。如果不想根据屏幕分辨率来调整图片大小,使用nodpi。
6、当应用不在前台时是可以显示toast的。例如:一个后台服务产生的toast在使用任何应用时都可以展示出来。
7、ScrollView里不能使用ListView
8、ImageView的android:scaleType属性
9、include标签
<include>标签唯一需要的属性是layout属性,它指定了要包括的布局文件。可重写已包含布局的根视图的layout_*属性,通过把他们添加到<include>标签中来改变它们的值。注意:只有android:layout_*属性和android:id属性可以被重写,所有其他属性都会被忽略。新的属性将会只应用到被包含布局的根节点上。如果你要重写android:layout_*属性中的一个,那么你必须重写android:layout_width和android:layout_height属性。
10、merge标签
merge标签指导系统移除子布局的顶层容器。当你包含一个子布局时,里面包含的视图会被合并到主布局中去,但没有额外的容器视图。
11、ViewStub类是一个不会占据布局空间的不可见的视图。它和<include>标签一样,引用一个将会被添加到UI上的外部布局。与<include>不同的是,被引用的布局不会被扩张,直到收到特定的请求它才扩张。有了ViewStub,布局的可选部分只会在你需要它们的时候可用,否则它们就会不可见。要使用ViewStub引用的外部布局,可以自己inflate它或者改变它的可见性。可以使用android:inflatedId来覆盖扩张的子布局的ID。
12、Android视图有3个可能的可见性状态
View.VISIBLE:视图对于用户可见,占据布局空间。
View.INVISIBLE:视图对于用户不可见,但还是会占据布局空间。
View.GONE:视图不可见,不占据布局空间。也不会被包含在布局和绘制过程中。
13、Android平台的默认资源在R类中可用,可以使用@android:前缀引用它们。
14、样式和主题的区别:应用到视图的样式只会应用到那个视图上,并不会应用到该视图的子视图上。可以通过主题来为一个活动的所有视图应用样式而不用为所有的视图一一指定样式,通过在应用清单上的<activity>或<application>元素上应用android:theme属性来做到这一点。
15、res与res-auto的区别
通常我们在布局文件中使用自定义属性的时候会这样写:
xmlns:app="http://schemas.android.com/apk/res/包路径"
但如果你当前工程是做为lib使用,那么你如上所写,会出现找不到自定义属性的错误。这时候你就可以写成:
xmlns:app="http://schemas.android.com/apk/res-auto"