一.所花时间
0.5h
二.代码量
40行
三.博客量
1篇
四.了解到的知识点
设置视图的间距
android:layout_marginTop="5dp" 该属性的作用是让当前视图与上方间隔一段距离
android:layout_marginLeft 让当前视图与左边间隔一段距离
android:layout_marginRight 让当前视图与右边间隔一段距离
android:layout_marginBottom 让当前视图与下方间隔一段距离
如果上下左右都间隔同样的距离,还能使用android:layout_margin一次性设置四周的间距
padding也是View的一个通用属性,它用来设置视图的内部间距,并且padding也提供了paddingTop、paddingBottom、paddingLeft、paddingRight四个方向的距离属性。
<!-- 最外层的布局背景为蓝色 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#00aaff"
android:orientation="vertical">
<!-- 中间层的布局背景为黄色 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#ffff99"
android:padding="60dp">
<!-- 最内层的视图背景为红色 -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000" />
</LinearLayout>
</LinearLayout>
浙公网安备 33010602011771号