xmlxamarinxamarin.androidandroid-layout-weight

When aligned to width LinearLayout layout_weight = “1” requires unit


I use android: layout_weight = "1" to align the elements, but I can't figure out why I need to specify the unit of measurement.

What is the reason for this?

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp">
        <Button
            android:text="+"
            android:layout_width="odp"
            android:layout_height="65dp"
            android:layout_weight="1"// requires a unit
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:id="@+id/bttnPlus"
            android:layout_marginRight="20.0dp" />
        <Button
            android:text="-"
            android:layout_width="odp"
            android:layout_height="65dp"
            android:layout_weight="1"// requires a unit
            android:background="@android:color/black"
            android:textColor="@android:color/white"
            android:layout_marginRight="20.0dp"
            android:id="@+id/bttnMinuse" />
    </LinearLayout>

Solution

  • It does not need a unit and it's an issue of Visua-Studio.

    In this thread:

    It should be fixed in the Visual-Studio v16.9 Preview.