티스토리 뷰

TextView 는 사용자에게 텍스트를 표시하기 위해 사용한다.
완벽한 text 편집기이지만, 기본적으로 편집을 할 수 없고 보여지는 텍스트는 수정할 수 있다.
How to
◼ TextView code in XML
<TextView | |
android:id="@+id/simple_textview" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" /> |
◼ TextView code in JAVA
TextView textView = (TextView) findViewById(R.id.simple_textView); | |
textView.setText("Parkho"); |
Attributes
◼ id
id 는 해당 TextView 를 유일하게 식별할 수 있는 속성이다.
<TextView | |
android:id="@+id/simple_textview" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> |
◼ gravity
Text 를 정렬할 수 있는 속성이다.
- layout_width, layout_height 이 wrap_content 이면 text 가 정렬될 공간이 없어 정렬이 안된다.
- gravity 를 지정하지 않으면 기본 속성인 left, top 이 적용된다.
[Android/Layout] - TextView gravity
<TextView | |
android:id="@+id/simple_textview" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center" | |
android:text="Parkho" /> |

◼ text
TextView 에 표시할 text 를 설정한다.
<TextView | |
android:id="@+id/simple_textview" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" /> |

◼ textColor
Text 의 색상을 설정한다.
- “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb” 형태로 지정할 수 있다.
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textColor="#FF0000" /> |

◼ textSize
Text 의 크기를 설정한다.
- sp(scale independent pixel) or dp(density pixel) 로 설정 할 수 있다.
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textSize="30.00sp" /> |

◼ textStyle
Text 의 style 을 설정한다.
- "bold"(굵게), "italic"(이태릭), "normal"(기본) 을 설정할 수 있고 "|" 로 2개 이상의 설정을 할 수 있다.
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:textStyle="bold | italic" /> |

◼ SingleLine
Text 를 한 줄로 표시할 때 사용한다.
- 기본값은 false
<TextView | |
android:layout_width="100.00dp" | |
android:layout_height="wrap_content" | |
android:background="#D3D3D3" | |
android:singleLine="true" | |
android:text="Parkho Parkho Parkho" /> |
![]() |
![]() |
[SingleLine = true] | [SingleLine = false] |
◼ ellipsize
Text 의 길이가 길어지는 경우 말줄임(...) 처리 방법
- start: 글자 첫 부분에 "..." 넣기
- none: "..." 없이 글자 잘림
- end: 글자 마지막 부분에 "..." 넣기
- marquee: marquee(글자가 왼쪽으로 흘러감) 처리
- middle: 글자 중간 부분에 "..." 넣기
<TextView | |
android:layout_width="100.00dp" | |
android:layout_height="wrap_content" | |
android:background="#D3D3D3" | |
android:singleLine="true" | |
android:ellipsize="none" | |
android:text="Parkho Parkho Parkho" /> |

◼ background
TextView 의 배경색을 설정한다.
- color 값이나 drawable 을 설정할 수 있다.
◼ padding
TextView 의 왼쪽, 오른쪽, 위, 아래 padding 을 설정한다.
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Parkho" | |
android:background="#00FF00" | |
android:padding="15.00dp"/> |

'Android > UI' 카테고리의 다른 글
CheckBox (0) | 2019.07.18 |
---|---|
EditText (0) | 2019.07.15 |
TextView gravity (0) | 2019.07.09 |
View & Viewgroup (0) | 2019.06.26 |
TextView 에 HTML 표현하기 (0) | 2019.05.17 |
- Total
- Today
- Yesterday
- 리워드앱
- registerForContextMenu
- notifyDataSetChanged
- task
- onContextItemSelected
- 안드로이드 서비스
- StartService
- p2e
- BroadcastReceiver
- task 생성
- 앱테크
- android task
- mPANDO
- 안드로이드 인텐트
- Android Service
- 무료채굴
- StringUtils
- M2E
- 앱테크 추천
- android intent
- 채굴앱
- 리워드 어플
- onCreateContextMenu
- WEMIX
- android activity flag
- RoomDatabase
- android flag activity
- 무료 채굴
- bindservice
- Intent
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |