๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - TextView ์†์„ฑ๋“ค(text, textColor, background, layout_margin, visibility, padding, gravity) ๋ณธ๋ฌธ

๐Ÿค–Android/Java

[Android] ์•ˆ๋“œ๋กœ์ด๋“œ - TextView ์†์„ฑ๋“ค(text, textColor, background, layout_margin, visibility, padding, gravity)

๋ฃจ๋ฆฌ์•ผใ…‘ 2023. 12. 21. 13:09
๋ฐ˜์‘ํ˜•

์•ˆ๋“œ๋กœ์ด๋“œ์˜ TextView๋Š” ํ™”๋ฉด์— ํ…์ŠคํŠธ๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” UI ์š”์†Œ์ด๋‹ค. ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ…์ŠคํŠธ, ์ƒ‰์ƒ, ๋ฐฐ๊ฒฝ, ๋ ˆ์ด์•„์›ƒ ๋“ฑ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์•ˆ๋“œ๋กœ์ด๋“œ TextView ์†์„ฑ

  1. text: TextView์— ํ‘œ์‹œ๋˜๋Š” ํ…์ŠคํŠธ ๋‚ด์šฉ์„ ์„ค์ •ํ•œ๋‹ค.
  2. textColor: ํ…์ŠคํŠธ์˜ ์ƒ‰์ƒ์„ ์ง€์ •ํ•œ๋‹ค.
  3. background: TextView์˜ ๋ฐฐ๊ฒฝ์„ ์„ค์ •ํ•œ๋‹ค. ๋ฐฐ๊ฒฝ์œผ๋กœ๋Š” ์ƒ‰์ƒ, ์ด๋ฏธ์ง€ ๋˜๋Š” Drawable ๋“ฑ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  4. layout_margin: TextView์˜ ์—ฌ๋ฐฑ์„ ์„ค์ •ํ•œ๋‹ค. layout_margin์„ ํ†ตํ•ด ์ƒํ•˜์ขŒ์šฐ ์—ฌ๋ฐฑ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  5. visibility: TextView์˜ ํ‘œ์‹œ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค. visible, invisible, gone ๋“ฑ์˜ ๊ฐ’์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
  6. padding: TextView ๋‚ด๋ถ€์˜ ํ…์ŠคํŠธ์™€ ํ…Œ๋‘๋ฆฌ(๊ฒฝ๊ณ„) ์‚ฌ์ด์˜ ์—ฌ๋ฐฑ์„ ์ง€์ •๋‹ค.
  7. gravity: TextView ๋‚ด์˜ ํ…์ŠคํŠธ๋ฅผ ์–ด๋””์— ์ •๋ ฌํ• ์ง€๋ฅผ ์„ค์ •ํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, center, start, end ๋“ฑ์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:text="์•ˆ๋…•ํ•˜์„ธ์š”."
        android:textColor="#B85252"
        android:background="#00ff00"
        android:layout_margin="20dp"
        android:visibility="invisible"
        android:padding="20dp"
        android:gravity="center"

</androidx.constraintlayout.widget.ConstraintLayout>

 

[์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค ๋””์ž์ธ ํ™”๋ฉด]

๋ฐ˜์‘ํ˜•