与宽度对齐时LinearLayout layout_weight =“ 1”需要单位

巴姆

我使用android:layout_weight =“ 1”来对齐元素,但是我不知道为什么需要指定度量单位。

这是什么原因呢?

<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>
杰克华-MSFT

它不需要一个单元,这是Visua-Studio的问题。

在这个线程中

它应该在Visual Studio中修复v16.9 Preview

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用layout_weight获取LinearLayout的高度(以像素为单位)

Android LinearLayout layout_weight 行为

Android在垂直LinearLayout中将layout_weight设置为宽度

使用weightSum和layout_weight时如何在LinearLayout元素上设置最小宽度

了解权重和layout_weight时,layout_weight越大,布局中的收缩就越大。

固定宽度的Android Layout_Weight不起作用

在LinearLayout上显示“ android:layout_weight”时,LinearLayout内的ImageView不显示

使用layout_weight使两个LinearLayout具有相同的高度,不起作用

没有layout_weight属性,LinearLayout中的片段不会出现

Android:layout_weight 不适用于 Button 和 LinearLayout

为什么相同的layout_weight导致Android ImageButton和Button的宽度不同?

如何使用layout_weight使宽度和高度[正方形]大小相等?

将layout_weight分配给微调器时,微调器上的SetSelection崩溃

使用wrap_content时不显示内容,也不使用layout_weight

RecyclerView-第一次加载时Layout_weight被忽略

当我向布局中添加视图时,layout_weight发生更改(Android)

layout_weight重叠视图

layout_weight如何工作?

layout_weight无法正常使用editfield

定义layout_weight为水平?

android- layout_weight =“ 0”的含义

使用layout_weight进行滚动视图

TableLayout,android:layout_weight,并包括

具有RelativeLayout的android layout_weight

如何修复线性布局中的layout_weight?

如何以编程方式设置layout_weight?

如何通过代码动态设置layout_weight属性?

具有不同布局类型的layout_weight

android:layout_weight是什么意思?