Android Studio [水平布局LinearLayout]

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     xmlns:app="http://schemas.android.com/apk/res-auto"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     android:orientation="vertical"
 9     tools:context=".MainActivity">
10 
11     <LinearLayout
12         android:id="@+id/ll_1"
13         android:layout_width="200dp"
14         android:layout_height="200dp"
15         android:background="#000000"
16         android:orientation="vertical"
17         android:padding="20dp">
18 
19         <View
20             android:layout_width="match_parent"
21             android:layout_height="match_parent"
22             android:background="#a42525" />
23 
24     </LinearLayout>
25     <LinearLayout
26         android:layout_width="match_parent"
27         android:layout_height="200dp"
28         android:orientation="horizontal"
29         android:background="#0066FF"
30         android:layout_marginTop="20dp"
31         android:gravity="center_vertical">
32         <View
33             android:layout_width="0dp"
34             android:layout_height="200dp"
35             android:background="#000000"
36             android:layout_weight="1"
37             />
38         <View
39             android:layout_width="0dp"
40             android:layout_height="200dp"
41             android:background="#ef0000"
42             android:layout_weight="1"
43             />
44     </LinearLayout>
45 </LinearLayout>

今天学习到的:

  

<LinearLayout  +代码
> </LinearLayout>水平布局
android:layout_width="?dp"宽度
android:layout_height="?dp"高度
android:background="#ef0000"背景颜色
android:layout_weight="1"块所占的权重
android:gravity="center_vertical">对齐方式
android:orientation="vertical"排列方式 水平/竖直
结果:

猜你喜欢

转载自www.cnblogs.com/zlc364624/p/10700833.html