0

LinearLayout で重みを分散しようとしています。ButtonView で動作しますが、単純なビューでは逆に動作します。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FF0000" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:background="#00FF00" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="#0000FF" />

</LinearLayout>

ここに画像の説明を入力

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FF0000" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:background="#00FF00" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="#0000FF" />

</LinearLayout>

ここに画像の説明を入力

それを正しく動作させるのは間違いなくButtonViewの実装です。しかし、LinearLayout の動作と一貫性を保つために、View に何 (およびどのように) を実装する必要があるのでしょうか? どうもありがとう。

4

2 に答える 2