Android

[Android] layout_width, width, minWidth, maxWidth

잘할수있을거야 2021. 7. 18. 03:20

TextView의 android:width, android:height 속성

TextView자기 자신의 고정된 크기를 자기 뷰에서 정하는 것

 

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#33111111"
        android:text="hello"/>

wrap_content-> default textSize값에 해당하는 "hello"의 컨텐트만큼의 크기가 TextView의 사이즈로 설정된다.


 

 

android:width, android:height속성을 추가하게 되면

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="100dp"
        android:height="100dp"
        android:background="#33111111"
        android:text="hello" />

wrap_content -> 100dp에 해당하는 너비, 높이 값이 TextView의 사이즈로 설정된다.


View의 android:minWidth, android:minHeight, android:maxWidth, android:maxHeight속성

 

EditText의 사용자 텍스트의 입력, ScrollView의 안에 담긴 이미지

이러한 콘텐트가 늘어남에 따라 뷰의 크기가 유동적으로 바뀌게 된다.

 

이러한 값을 설정할 수 있는것이 바로 위의 min,max속성이다.

 

EditText를 예로 들어보자.

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="150dp"
        android:minWidth="100dp"
        android:textSize="15sp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="100dp"
        android:text="100dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="150dp"
        android:text="150dp" />

가로는 100dp~150dp까지 늘어날 수 있는 EditText이다. 현재 android:text 설정이 없으므로 화면에 그려지면 100dp로 그려진다.

 

사용자가 글자를 입력하다 100dp를 넘으면 자동으로 View가 커지다가 150dp까지 커진다.

 

150dp를 넘으면 그 다음 줄로 이동한다.

maxHeight를 지정하지 않았기 때문에 높이가 유동적으로 늘어나서

이 EditText밑에 다른뷰들이 있다면 점점 밑으로 밀려나게 된다.

 


TextView포함 상속받은 Widget들에서 android:width속성과 min,max속성을 같이 쓰게되면 min,max속성은 무시된다.( 길이가 고정됨)