[안드로이드 프로그래밍] 텍스트를 넣어보자 :텍스트 뷰:

프로그래밍/Android 2016.03.12 댓글 Plorence

 

  • 먼저 시작전에, Hello World! 라는 텍스트를 출력시켜 보여드리겠습니다.

강좌를 잘 따라오신다면 Hello World! 부분의 텍스트를 자기맘대로 설정하고 출력이 가능합니다. 

 

"텍스트 뷰" 란?

 

텍스트 뷰 라는건 말 그대로 텍스트를 넣는 뷰 입니다.

사용 용도는 내가 원하는 텍스트를 넣고싶을때 주로 사용을 합니다.

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.test.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
 

처음 프로젝트를 만들었을때 기본적으로 생성되는 레이아웃과 뷰입니다

우리는 텍스트 뷰를 건드릴 것 이기 때문에 다른것은 생략합시다.

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

 

이게 텍스트 뷰입니다.

처음 안드로이드 접하시면 뭐가뭔지 하나도 모르실 겁니다.

한줄한줄 씩 설명해드리겠습니다.

 

    <TextView //텍스트뷰 라는 뷰의 종류중 하나입니다.//
        android:layout_width="wrap_content"  //가로를 내용물의 크기만큼 설정합니다//
        android:layout_height="wrap_content" //세로를 내용물의 크기만큼 설정합니다//
        android:text="Hello World!" /> //Hello World! 라는 텍스트를 출력합니다//

 

그럼 이제 Hello World! 라고 출력되는 텍스트를 안녕하세요! 라고 텍스트를 출력시켜보겠습니다.

 

android:text="Hello World!" 부분을

 

android:text="안녕하세요!"

 라고 수정을 하면

이렇게 안녕하세요! 라는 텍스트를 출력시켰습니다.

 

이것으로 텍스트 뷰 강좌를 마치겠습니다. 감사합니다.

 

댓글