안드로이드 01

오늘·2021년 6월 11일
0

안드로이드

목록 보기
1/2

자동저장

텍스트 화면에서 수정한 XML이나 자바 소스 코드는 자동으로 저장됩니다. 근데 좀 불안하다면 ctrl+s 로 저장을 생활화합시다.

사용한 값들

android:layout_width=""
android:layout_height=""
: 높이와 넓이
android:orientation=""
: 수평, 수직
android:layout_weight="1"
: 가중치


android:text=""
: 출력할 글자
android:textSize=""
: 글자 사이즈
android:gravity=""
: 글자 위치
android:textStyle=""
: 글자 진하게
android:textColor=""
: 글자 색
android:background=""
: 배경 색

activity_main.xml

전체 코드 보기

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_weight="1" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="1열"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#37978E"
            android:background="#BEF183"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="2열"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#EADD6C"
            android:background="#EFBD74"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="3열"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#8F71C5"
            android:background="#784F80"
            android:layout_weight="1"
            />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="1행"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#37978E"
            android:background="#BEF183"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="2행"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#EADD6C"
            android:background="#EFBD74"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="3행"
            android:textSize="20sp"
            android:gravity="center"
            android:textStyle="bold"
            android:textColor="#8F71C5"
            android:background="#784F80"
            android:layout_weight="1"
            />
    </LinearLayout>
</LinearLayout>

현재 화면 상황


수평, 수직으로 설정해 놓은대로 출력되는 모습. 설정한 글자색/배경색으로 출력되는 모습 확인


텍스트뷰로 텍스트 출력

strings.xml

<resources>
    <string name="app_name">시목록</string>
    <String name="title1">별 헤는 밤</String>
    <String name="author1">윤동주</String>
    <String name="body1">
        계절이 지나가는 하늘에는
        가을로 가득 차 있습니다.

        나는 아무 걱정도 없이
        가족 속의 별들을 다 헤아릴듯 합니다.
    </String>

    <String name="title2">가지 않는 길</String>
    <String name="author2">로버트 프로스트</String>
    <String name="body2">
        단풍 든 숲 속에 두 갈래 길이 있습니다.
        한 몸이 두 갈래를 가지 못하기에
        탄식하며 한참을 서서
        낮을 수풀로 꺽여 내려가는 길을
        멀리 바라보았습니다.
    </String>
</resources>

activity_main.xml

android:padding = ""
: 패딩 값 주기(컨텐츠와 글자 사이의 간격)
-> paddingTop, paddingBottom, paddingRight, paddingLeft 로 상세 설정 가능

android:layout_height="wrap_content"
: 글씨(컨텐츠)의 크기 만큼 높이를 주겠다
android:layout_width="match_parent"
: 글씨(컨텐츠)의 크기와 상관없이 전체적으로 먹겠다
android:ellipsize="marquee"
: 글씨(컨텐츠)가 수평으로 쭉 흘러감
android:ellipsize="end"
: 뒷 부분을 생략해서 ...으로 표현
android:ellipsize="start"
: 앞 부분을 생략해서 ...으로 표현

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="20dp"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title1"
        android:textSize="18sp"
        android:gravity="center"
        android:textStyle="bold"
        android:background="#FFC5C5"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/author1"
        android:textSize="15sp"
        android:background="#F6E5B3"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/body1"
        android:textSize="15sp"
        android:textStyle="normal"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:background="#FFF8BC"
        />


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title2"
        android:textSize="18sp"
        android:gravity="center"
        android:textStyle="bold"
        android:background="#E7FFCB"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/author2"
        android:textSize="15sp"
        android:background="#A6D8FF"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/body2"
        android:textSize="15sp"
        android:textStyle="normal"
        android:singleLine="true"
        android:ellipsize="end"
        android:background="#838BB8"
        />

</LinearLayout>

실행

애뮬레이터를 실행시키는 방법은 여기를 참조했다

사진이 너무 크다 실행시키면 이런 화면이 뜬다. 구분하기 위해서 빨주노초파남으로 색을 지정해줬더니 무지개 떡 같다


이미지 출력

이미지 리소스는 drawable 폴더에 저장하여 사용할 것이며, 이미지 뷰를 통해 화면에 출력할 것이다.

이미지 넣기

텍스트 편집

strings.xml

<resources>
    <string name="app_name">이미지 출력</string>
    <string name="hello_world">Hello World</string>
    <string name="action_settings">Settings</string>
    <string name="title">Starry Night</string>
    <string name="artist">고흐</string>
    <string name="desc">
        고흐 작품 상세 설명
        (이하 생략)
    </string>
</resources>

activity_main.xml

android:adjustViewBounds="true"
: 실제 그림의 가로/세로 비율을 맞춰서 조정
android:src=""
: 해당 위치에 있는 그림을 가져올 것이다

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title"
        android:textSize="18sp"
        android:gravity="center"
        android:textStyle="bold"
        android:textColor="#492B0B">
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/artist"
        android:textSize="15sp"
        android:gravity="right"
        android:textStyle="bold"
        android:textColor="#19321A"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="10dp"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/starry_night"
        android:maxWidth="120dp"
        android:maxHeight="120dp"
        android:adjustViewBounds="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="20dp"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/desc"
        android:textSize="15sp"
        android:textColor="#613808" />
</LinearLayout>

실행


아무래도 글자가 너무 벽에에 붙어있어서 별로니 margin을 줘야겠다

<TextView>에 전체적으로 android:layout_margin="20dp" 을 추가해줬다

글씨들이 벽에서 좀 떨어졌다 좋다.

0개의 댓글