1.View指定视图最小宽高
-
minWidth:指定该视图的最小宽度
-
minHeight:指定该视图的最小高度
2.View属性layout_gravity可选项
XML中的对齐方式 | Gravity类中的对其方式 | 说明 |
left | LEFT | 靠左对齐 |
right | RIGHT | 靠右对齐 |
top | TOP | 向上对齐 |
bottom | BOTTOM | 向下对齐 |
center | CENTER | 居中对齐 |
center_horizontal | CENTER_HORIZONTAL | 水平方向对齐 |
center_vertical | CENTER_VERTICAL | 垂直方向对齐 |
3.3种java中设置View背景的方法
-
setBackgroundColor:设置该视图的背景颜色
-
setBackgroundDrawable:设置该视图的背景图片
-
setBackgroundResource:设置该视图的背景资源id
4.ViewGroup的三个独有方法
-
addView:往布局中添加一个视图
-
removeView:从布局中删除指定视图
-
removeAllViews:删除该布局下的所有视图
5.java中设置LinearLayout方向的方法
-
setOrentation:设置线性布局的方向。LinearLayout.HORIZONTAL表示水平布局,LinearLayout.VERTICAL表示垂直布局。
6.两种滚动视图
-
ScrollView:垂直滚动视图
-
HorizontalScrollView:水平滚动视图
7.滚动视图使用的三点注意事项
-
垂直方向滚动时,layout_width要设置未match_parent,layout_height要设置为wrap_content。
-
水平方向滚动时,layout_widht要设置为wrap_content,layout_height要设置为match_parent。
-
滚动视图节点下面必须且只能挂着一个子布局节点,否则会再运行时报错。
8.滚动视图举例
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#00ff00"/>
<View
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="#ffffaa"/>
</LinearLayout>
</ScrollView>
9.滚动视图内容不足充满屏幕方法
android:layout_height="match_parent"
android:fillViewport="true"
在ScrollView上添加这两个属性即可