์ƒˆ์†Œ์‹

Languages/Android

[Android] View | Widget

  • -
๋ฐ˜์‘ํ˜•

https://greenhelix.tistory.com/164

์•ˆ๋“œ๋กœ์ด๋“œ ๋ชจ๋“  ๊ธ€์€ ๊ฐœ์ธ ๊ณต๋ถ€, ๊ฐœ๋ฐœ ๋ชฉ์ ์ด๋ผ ๊ฐœ๋…์— ๋Œ€ํ•œ ์„ค๋ช…์ด ์ œ๋Œ€๋กœ ๋“ค์–ด๊ฐ€์ง€ ์•Š์œผ๋‹ˆ, ์ฐธ๊ณ ํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.


 

 

View

ํ…์ŠคํŠธ ๋ทฐ์˜ text์†์„ฑ ์ง€์ • ๋ฐฉ๋ฒ•์€ 2๊ฐœ๊ฐ€ ์žˆ๋‹ค.

 

- ๊ทธ๋ƒฅ text ์†์„ฑ ์ถ”๊ฐ€(๋””์ž์ธ์—์„œ ๊ฑด๋“œ๋ ค์„œ)

- strings.xml ํŒŒ์ผ ๊ฑด๋“œ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•

 

์ด๋ฒˆ์—” ์•„๋ž˜ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹ค์Šตํ•ด๋ณด์ž.

 

์•„๋ž˜ ์ฒ˜๋Ÿผ strings.xmlํŒŒ์ผ์— ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

 

๋‹ค์Œ ๋””์ž์ธ์—์„œ text view๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๊ณ , ์†์„ฑ text์˜ ๊ฐ’์„ @string/person_name์œผ๋กœ ํ•ด์ฃผ๋ฉด 

์ง€์ •ํ•œ ์ด๋ฆ„์ธ "์ดํ•˜์€"์ด textView์— ๋ณด์ด๊ฒŒ ๋œ๋‹ค.

 

์ฐธ๊ณ ๋กœ ์•ˆ๋“œ๋กœ์ด๋“œ์—์„œ ๋‹ค๊ตญ์–ด๋ฅผ ์ง€์›ํ•จ.

- ๋ฆฌ์†Œ์Šค์— ๊ณตํ†ต ์ ์šฉ๋˜๋Š” ๋ณ‘๋ ฌ ๋ฆฌ์†Œ์Šค ๋กœ๋”ฉ๋ฐฉ์‹์„ ์‚ฌ์šฉ

- app/res ํด๋” ์•ˆ์— ๋‘ ๊ฐœ์˜ ํด๋” ๋งŒ๋“ค ๊ณ  strings.xmlํŒŒ์ผ์„ ๋„ฃ์œผ๋ฉด ๋จ.

์ถœ์ฒ˜ : ์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ๊ฐœ๋ฐœ ๊ต์žฌ(do it)

์œ„์™€ ๊ฐ™์ด ์ด๋ฆ„์„ ์ง€์ •ํ•ด์„œ ํ•ด์ฃผ๋ฉด ๋จ. (ํ•œ๊ธ€ ์ง€์›์ด ๋˜๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋†“๊ณ  ๊ทธ xmlํŒŒ์ผ์—์„œ ํ•œ๊ตญ์–ด๋กœ ์ž‘์„ฑํ•˜๋ฉด ๋จ)

 

 

textView ์†์„ฑ

 

- textColor : ํ…์ŠคํŠธ ์ƒ‰์ƒ ์„ค์ •

- textSize : ํ…์ŠคํŠธ ์‚ฌ์ด์ฆˆ

- textStyle : ํ…์ŠคํŠธ ์Šคํƒ€์ผ ์†์„ฑ(๋‘๊ป๊ฒŒ ๋“ฑ..)

- textFace : ํ…์ŠคํŠธ ํฐํŠธ(๋‹ค์šด๋กœ๋“œ ๋ฐ›์•„์„œ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์Œ)

-maxlines : ํ…์ŠคํŠธ ๋ทฐ์—์„œ ํ‘œ์‹œํ•˜๋Š” ๋ฌธ์ž์—ด์˜ ์ตœ๋Œ€ ์ค„ ์ˆ˜ ์ง€์ •

 

์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€๋‹ค๊ณ  ํ•˜๋ฉด 2๋ฒˆ์งธ textView๊ฐ€ ์ตœ๋Œ€ 1์ค„๊นŒ์ง€๋งŒ ํ—ˆ์šฉ๋˜๋ฉฐ ๋‚˜๋จธ์ง€ ๊ธ€์ž๊ฐ€ ๋ชจ๋‘ ๋ณด์ด์ง€ ์•Š๋Š” ๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Œ.

<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/person_name" android:textColor="#FF0000" android:textSize="40sp" android:textStyle="bold" android:typeface="serif" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="1" android:text="์ด๊ณณ์— ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด๋ณด์ž. ํ•œ์ค„๋กœ ํ‘œ์‹œ๋˜๋‚˜?" android:textColor="#000000" android:textSize="40sp" android:textStyle="bold" android:typeface="serif" />

 

 

button ์˜ˆ์ œ:)

<?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:gravity="center" android:orientation="vertical" tools:context=".MainActivity" > <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="์„ ํƒ" android:textSize="24sp" android:textStyle="bold" /> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:id="@+id/radioButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="RadioButton" /> </RadioGroup> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal|center_vertical" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="CheckBox" /> </LinearLayout> </LinearLayout>

 

 

tip1) extract string resource

 

1. res -> values -> strings.xml์—๋‹ค๊ฐ€ ๋„ค์ž„์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•

2. ๋…ธ๋ž€ ์ „๊ตฌ ํด๋ฆญ ํ›„

 

 

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.