-
内外边距属性
外边距 内边距 layout_margin 外边距 padding 内边距 layout_marginTop 上边距 paddingTop 上内边距 layout_marginBottom 下边距 paddingBottom 下内边距 layout_marginLeft 左边距 paddingLeft 左内边距 layout_marginRight 右边距 paddingRight 右内边距 注意:
layout_margin
与padding
不能像css
中可以填写一次性填写四个方位的间距值,只能填写单个间距值,也就是四周统一用一个值。android:padding="40dp 40dp 40dp 40dp" × android:padding="40dp" √
-
布局案例
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!-- 由于最外层不是 Layout,则这里为根布局 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffc"> <!-- 再添加一个内部视图布局 --> <LinearLayout android:layout_marginTop="200dp" android:layout_marginLeft="70dp" android:layout_width="300dp" android:layout_height="300dp" android:padding="40dp" android:background="#fcf"> <!-- 添加视图组件 --> <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cff"/> </LinearLayout> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Android XML 布局基础(四)内外边距(margin、padding)
最新推荐文章于 2024-11-01 17:55:32 发布