선형 레이아웃 (LinearLayout)에는 특정 분석을위한 렌더링 및 소스 코드에 대한 많은 지식 포인트가 포함되어 있습니다.
효과 사진 :
소스 코드 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="300dp"
android:layout_height="300dp"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center|top"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_weight="1">
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_weight="1">
</Button>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_weight="1">
</Button>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮4">
</Button>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮5">
</Button>
</LinearLayout>
android : orientation은 수평 수평 및 수직 수직으로 나뉘는 선형 배열입니다.
android : layout_gravity는 상위 컨테이너에서 전체 LinearLayout의 상대적 위치입니다. 많은 속성이 사용되는 경우 확인하십시오. 예를 들어 center는 중앙입니다.
android : gravity . 컨테이너에서
android : layout_weight 의 상대적 위치는 가중치입니다. 가중치는 레이아웃의 요소가 차지하는 공간의 비율을 결정합니다. 가중치가 동일하면 공간이 균등하게 분할됩니다.
중첩 레이아웃 : 하나의 레이어 만 중첩 LinearLayout에서 표시된 버튼 3 효과