πŸ€–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>

 

[μ•ˆλ“œλ‘œμ΄λ“œ μŠ€νŠœλ””μ˜€ λ””μžμΈ ν™”λ©΄]

λ°˜μ‘ν˜•