android: LinearLayout中指定间距
一,代码:
xml:
<?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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.PreferenceActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Space
android:layout_width="match_parent"
android:layout_height="66dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:layout_gravity="center"
android:text="控件1"
android:layout_marginBottom="66dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="66dp"
android:background="#ffff00"
android:layout_gravity="center"
android:text="控件2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
说明:
可以用<Space>来指定高度,
也可以用layout_margin来指定间距
二,测试效果:

浙公网安备 33010602011771号