繁体   English   中英

wrap_content TextViews之间的layout_weight TextViews未对齐

[英]layout_weight TextViews between wrap_content TextViews not aligned

我是android编程的新手,现在由于无法解决的问题而停下来。

我创建了以下布局:

[TextView wrap_content] [TextView weight = 5] [TextView weight = 5] [TextView wrap_content]

编译如下截图:

屏幕

如您所见,第二个TextView已正确对齐。 问题是第三和第四TextView。 第三个不与第二个对齐,也不会与最大的TextView对齐

这有可能吗?

这是我的布局:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="horizontal"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content">

    <TextView

    android:id="@+id/SetCard_Item_txtCount"

    android:layout_marginLeft="2dp"

    android:layout_marginRight="2dp"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:textSize="14dp" />

<TextView

    android:id="@+id/SetCard_Item_txtName"

android:layout_width="0dp"

android:layout_weight="5"

android:layout_marginLeft="2dp"

    android:layout_marginRight="2dp"

    android:layout_height="wrap_content"

    android:textSize="14dp" />

    <TextView 

    android:id="@+id/SetCard_Item_txtType"

    android:layout_width="0dp"

android:layout_weight="5"

android:layout_marginLeft="2dp"

android:layout_marginRight="2dp"

    android:layout_height="wrap_content"

    android:textSize="14dp" />

    <TextView

    android:id="@+id/SetCard_Item_txtCost"

    android:layout_width="wrap_content"

    android:layout_marginLeft="2dp"

    android:layout_marginRight="2dp"

    android:layout_height="wrap_content"

    android:textSize="14dp" />

   </LinearLayout>

亲切的问候

每行上都有几个具有不同宽度的layout_width="wrap_content"元素。 布局权重机制仅适用于第二遍布局,与元素权重成比例地分配所有剩余空间。 不能保证对齐。

您可以将所有元素0dp宽度设置为非零宽度,以使其按所需方式对齐。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM