BACK-END/Android

[Android] weight 가중치

단비_danbee 2020. 11. 12. 10:56

가중치 = HTML로 따지면 colspan 같이 자리를 몇개 가지겠다고 선언해주는것.

 

0 버튼의 가중치는 2이다. 버튼 2개만큼의 자리를 차지.

 

예제
<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_weight="1">

            <Button
                android:text="0"
                android:textSize="14pt"
                android:id="@+id/num0"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2" <!--가중치 2-->
                android:onClick="num"/>
            <Button
                android:text="."
                android:textSize="16pt"
                android:id="@+id/point"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="num"/>
            <Button
                android:text="="
                android:textSize="14pt"
                android:id="@+id/equal"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="equal"/>
        </LinearLayout>