상세 컨텐츠

본문 제목

[안드로이드] LinearLayout 쉽게 사용하는 방법

안드로이드

by aries574 2022. 4. 16. 12:48

본문


이번 시간에는 LinearLayout을 쉽게 

사용하는 방법에 대하여 알아보겠습니다.

LinearLayout은 화면의 내용들을 가로나

세로 형태로 배치해줍니다. 

가로, 세로를 섞어서 사용할 수도 있습니다.

직접 만들어보면 어렵지 않습니다. 

그럼 시작하겠습니다. 


목차

1. 실행 화면

2. 메인 화면 구성 activity_main.xml


1. 실행 화면

 

2. 메인 화면 구성 activity_main.xml

 - 설명 - 

1. LinearLayout는 가로,세로 배치를 할 수 있게 도와주는

 레이아웃입니다.

 2. 가로, 세로를 정해주는 옵션은 orientation입니다.

 3. orientation의 값이 horizontal: 가로, vertical: 세로

 로 배치를 해줍니다.

 4. LinearLayout안에 LinearLayout을 배치하여 가로, 세로를

 섞어서 보여줄 수도 있습니다. 

 5. width의 값을 0으로 하고, layout_weight=1로 해줌으로써

 화면에 배치를 알아서 가득 채워줍니다. 

 6. marginTop를 통해 위의 뷰와 거리를 띄어줍니다. 

<LinearLayout 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/mainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <!-- 가로 정렬-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_green_light"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_light"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_orange_light"/>
    </LinearLayout>

    <!-- 세로 정렬 -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@android:color/holo_green_light"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@android:color/holo_blue_light"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@android:color/holo_orange_light"/>
    </LinearLayout>

    <!-- 가로 세로 혼합-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_red_dark"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_blue_dark"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_purple"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_green_light"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_red_light"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_orange_light"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_purple"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_blue_light"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="@android:color/holo_green_light"/>
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

2022.04.15 - [안드로이드] - [안드로이드] 클립보드(Clipboard) 텍스트 복사(Copy)&붙여 넣기(paste) 하는 방법

 

[안드로이드] 클립보드(Clipboard) 텍스트 복사(Copy)&붙여넣기(paste) 하는 방법

이번 시간에는 텍스트를 길게 누르면 복사를 해서 원하는 부분에 붙여 넣기 하는 방법을 알아보겠습니다. 목차 1. 실행 화면 2. 메인 화면 구성 activity_main.xml 3. 메인 코드 구현 MainActivity.java 1. 실

aries574.tistory.com

2022.04.14 - [안드로이드] - [안드로이드] 레이아웃 배경색상 애니메이션 적용하는 방법

 

[안드로이드] 레이아웃 배경색상 애니메이션 적용하는 방법

이번 시간에는 레이아웃 배경 색상에 애니메이션 적용하는 방법에 대하여 알아보겠습니다. 목차 1. 실행 화면 2. 색상 파일 만들기 3. 메인 화면 구성 activity_main.xml 4. 메인 코드 구현 MainActivity.java

aries574.tistory.com

2022.04.13 - [안드로이드] - [안드로이드] RecyclerView 다중 화면 적용하는 방법

 

[안드로이드] RecyclerView 다중 화면 적용하는 방법

RecyclerView를 사용하는 방법은 데이터를 보여줄 화면(xml) 하나와 어뎁터를 통해 데이터와 화면을 연결해서 RecyclerView에 보여줍니다. 만약에 데이터별로 각자 다른 화면에 보여주고 싶다면 어떻게

aries574.tistory.com

반응형

관련글 더보기

댓글 영역