[Android]์๋๋ก์ด๋ - TextView์ ํ ์คํธ ๊ธธ์ด๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ(maxLines, ellipsize)
์๋๋ก์ด๋์์ TextView์ ๊ธธ์ด๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ํฌ๊ธฐ์ ๊ด๋ จ๋ ์ฌ๋ฌ ๊ฐ์ง ์์ฑ์ ์ฌ์ฉํ์ฌ ์กฐ์ ํ ์ ์๋ค.
์ฃผ๋ก ์ฌ์ฉ๋๋ ์์ฑ์ผ๋ก๋ layout_width, layout_height, maxLines, ellipsize ๋ฑ์ด ์๋ค.
๊ฐ ์์ฑ์ ์ญํ ๊ณผ ์์ ์ฝ๋๋ฅผ ์์๋ณด์.
1. layout_width ์ layout_height
TextView์ ๋๋น์ ๋์ด๋ฅผ ๊ฒฐ์ ํ๋ค. ๋ค์๊ณผ ๊ฐ์ ๊ฐ๋ค์ ๊ฐ์ง ์ ์๋ค.
- wrap_content: TextView๊ฐ ํฌํจํ๋ ๋ด์ฉ์ ๋ง๊ฒ ํฌ๊ธฐ๊ฐ ์กฐ์ ๋จ.
- match_parent ๋๋ fill_parent: ๋ถ๋ชจ ๋ ์ด์์์ ๋๋น ๋๋ ๋์ด์ ๊ฐ์์ง.
- ๊ณ ์ ํฌ๊ธฐ(์: 100dp): ๊ณ ์ ๋ ํฌ๊ธฐ๋ก ์ค์ .
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!" />
2. maxLines
TextView์ ํ์ํ ์ต๋ ์ค ์๋ฅผ ์ง์ ํ๋ค.
์ด ์์ฑ์ TextView๊ฐ ๋๋ฌด ๊ธธ์ด์ง ๋ ํ
์คํธ๋ฅผ ์๋ฅผ ์ ์๋ค.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="This is a long text that will be truncated after two lines." />
3. ellipsize
TextView๊ฐ ์ต๋ ์ค ์์ ๋๋ฌํ ๋ ํ
์คํธ๋ฅผ ์๋ฅผ ๋ ์ฌ์ฉ๋๋ ํ์ ๋ฐฉ๋ฒ์ ์ง์ ํ๋ค.
์๋ฅด๋ ๋ถ๋ถ์ ๋ํ ํ์๋ฅผ ์ค์ ํ ์ ์๋ค.
- end: ๋ ๋ถ๋ถ์ "..."๋ฅผ ํ์
- start: ์์ ๋ถ๋ถ์ "..."๋ฅผ ํ์
- middle: ์ค๊ฐ ๋ถ๋ถ์ "..."๋ฅผ ํ์
- marquee: ํ ์คํธ๊ฐ ๋๋ฌด ๊ธธ ๊ฒฝ์ฐ ํ๋ฌ๊ฐ๋ ํจ๊ณผ๋ฅผ ์ค๋ค.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:text="This is a long text that will be truncated at the end." />
์์ ์์ ์ฝ๋์์๋ ๊ฐ ์์ฑ์ ์ฌ์ฉํ์ฌ TextView์ ๊ธธ์ด๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋ค.
ํ์์ ๋ฐ๋ผ ์ด๋ฌํ ์์ฑ์ ์กฐํฉํ์ฌ ํ
์คํธ ๋ทฐ์ ๋ชจ์์ ์ํ๋๋๋ก ์กฐ์ ํ ์ ์๋ค.