Layout_01.LinearLayout

WACK·2023년 6월 5일

뷰를 화면에 배치해주는 ViewGroup의 서브 클래스

  • LinearLayout
  • RelativeLayout
  • FrameLayout
  • GridLayout
  • ConstraintLayout

Layout 대체

  • 동일한 화면을 다양한 Layout으로 구성가능

Layout 중첩

  • 하나의 화면을 여러 Layout클래스를 중첩해서 작성

LinearLayout

  • 뷰 객체를 가로 혹은 세로 방향으로 나열하는 레이아웃
  • orientation 속성으로 방향 지정, vertical 혹은 horizontal
  • android:orientation=“vertical”
  • weight : 여백 자동 확장 속성
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=“2"
android:text="Button3"/>
</LinearLayout>
  • gravity, layout_gravity
    • 정렬을 위한 속성
    • gravity : 뷰 영역내에서의 뷰의 컨텐츠 정렬
    • layout_gravity : 뷰를 부모 영역내에서 정렬
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#FF0000"
android:textSize="15dp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:text="HelloWorld"
android:gravity="right|bottom"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#FF0000"
android:textSize="15dp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:text="HelloWorld"
android:gravity="center"/>
</LinearLayout>
profile
앱 개발자 지망생

0개의 댓글