singleLine = "true" 로 처리하였는데 deprecated 되었다. 이 문제로 구글링을 해보면 여러 말이 있지만 테스트 해보면 정확하지 않아서 한번 테스트 해보았다.
![](https://github.com/kkangseongyun/kkangs_share/blob/main/event_android_kotlin.jpg?raw=true)
maxLines vs lines
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="lines" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FF0000FF" android:lines="3"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="maxLines" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FF0000FF" android:maxLines="3"/> |
단순하게 lines="3" 과 maxLines="3" 으로 테스트 하였다.
lines의 경우는 처음부터 3줄 사이즈를 확보하여 출력되었지만 maxLines 의 경우는 1줄 사이즈로 출력되었다.
글을 입력해 보면 아래처럼 나온다.
lines 의 경우는 화면 사이즈는 3줄 사이즈로 고정되고 아래로 무한 스크롤 되면서 입력이 된다.
maxLines의 경우 처음 1줄 입력 사이즈로 나오다가 글을 입력하면 3줄까지 화면이 늘어나고 그 이후 입력은 3줄로 고정되고 무한 스크롤 입력이 된다.
inputType 과 같이 사용시
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="lines" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:lines="3" android:inputType="text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="maxLines" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="3" android:inputType="text" /> |
inputType="text" 로 설정한 경우이다.
inputType을 설정하면 lines 와 maxLines 가 전혀 적용되지 않는다. 두 경우 1줄 화면사이즈로 나오고 입력도 한줄만 입력이 된다.
결론
singleLine 이 deprecated 되었지만 여전히 사용해도 문제는 없다.
singleLine을 대체할 방법은 inputType 설정이다. inputType 설정만으로 한줄 입력
inputType 설정하면서 여러줄 입력을 허용하고 싶으면 textMultiLine 을 같이 설정하면 된다.
maxLines 와 lines 의 차이는 결국 UI 적인 측면이다. 초기 부터 몇줄 입력 사이즈를 확보해야 하는 경우 lines, 처음에는 한줄로 나오다가 늘어나서 몇줄 입력으로 고정되고 싶은경우는 maxLines
![](https://github.com/kkangseongyun/kkangs_share/blob/main/event_android_kotlin.jpg?raw=true)
'Android' 카테고리의 다른 글
Android MVC, MVVM, MVP (0) | 2017.07.20 |
---|---|
Android Studio를 이용해 쉽게 SHA1 지문 확인하기 (0) | 2017.07.18 |
Android AVD Camera webcam (0) | 2016.11.08 |
Android FCM(Firebase Cloud Messaging) (0) | 2016.06.29 |
Error : Unsupported major.minor version 52.0 (0) | 2016.06.21 |