본문 바로가기

Etc/android

[android] 안드로이드 레이아웃 비율 설정 (layout_weight)

728x90
반응형

레이아웃에 포함된 하위 컴포넌트들의 비율을 설정해 놓고 크기 변동에 따라 동적으로 변화시키기 위함 

1. 예로 아래와 같은 형태로 만들어 보고자 한다면

아래처럼 해보면 됨. 

Text 대신 ImageView로 하면 이미지로 설정가능하겠음. 

 

2.상위에 weigthSum을 설정하고 그 하위에서 비율을 고려해서 weight를 설정

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="10"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="<">
        </TextView>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:text="Title">
        </TextView>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="|"
            android:layout_weight="1"
            >
        </TextView>
    </LinearLayout>
728x90
반응형