[Android] 5가지 일반적인 레이아웃 방법에 대한 자세한 설명(그래픽 + 예제) 지속적으로 업데이트...

1. 레이아웃 개요

1 선형 레이아웃 가로 세로로 배열
2 상대 레이아웃 상대 위치에 따라 정렬
프레임 레이아웃 빈 영역을 열면 프레임의 컨트롤(레이어)이 겹쳐집니다.
4 테이블 레이아웃 표 배열
5 제약 레이아웃 레이아웃을 시각적으로 작성

2. 선형 레이아웃

1. 속성

안드로이드:아이디 고유한 가치
안드로이드:layout_height

높은,

wrap_content: (내용에 따라 변경, auto와 유사),

match_parent: (상위 요소와 동일)

단위는 바람직하게는: dp

안드로이드:layout_width 위와 같이 넓은
안드로이드:배경 배경색
안드로이드:layout_margin 여유
안드로이드:layout_padding
안드로이드:방향 수평 수평 배열; 수직 수직 배열
안드로이드:layout_weight 보기, 동일한 무게
안드로이드:중력 중앙

1. 가로 배열 android:orientation="horizontal"

 

​​<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮1"
        android:layout_marginTop="20dp"

        />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        />
    <Button
        android:id="@+id/button3"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="按钮3"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        />


</LinearLayout>

1. 세로 배열 android:orientation="vertical"

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮1"
        android:layout_marginTop="20dp"

        />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮2"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        />
    <Button
        android:id="@+id/button3"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="按钮3"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dp"
        />


</LinearLayout>

 

.

추천

출처blog.csdn.net/dxnn520/article/details/123703661