Android-奇怪的文本视图行为

Android-奇怪的文本视图行为,android,android-widget,textview,Android,Android Widget,Textview,我有点困惑,我目前正在设计一个活动的UI,并且所述UI中的两个TextView小部件的行为有点奇怪 我已经将背景设置为android:background=“#CCCCCC”,以便更容易地观察行为,当我获得我想要的外观时,它最终将被删除 当TextView都为空时,行为就是我从UI中期望的: 但是当TextView中填充了不同长度的字符串时,宽度会发生变化: 下面是附加到我的UI行的代码 <TableRow android:weightSum="2" >

我有点困惑,我目前正在设计一个活动的UI,并且所述UI中的两个
TextView
小部件的行为有点奇怪

我已经将背景设置为android:background=“#CCCCCC”,以便更容易地观察行为,当我获得我想要的外观时,它最终将被删除

TextView
都为空时,行为就是我从UI中期望的:

但是当
TextView
中填充了不同长度的字符串时,宽度会发生变化:

下面是附加到我的UI行的代码

        <TableRow android:weightSum="2" >
            <TextView
                android:id="@+id/tvDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#CCCCCC"
                android:gravity="center_vertical|center_horizontal"
                android:padding="4dp"
                android:textColor="#000000" />

            <View
                android:layout_width="8dp"
                android:layout_height="fill_parent" />

            <TextView
                android:id="@+id/tvTime"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#CCCCCC"
                android:gravity="center_vertical|center_horizontal"
                android:padding="4dp"
                android:textColor="#000000" />
        </TableRow>

到目前为止,我已经尝试将
android:layout\u width
参数更改为大量具有不同
android:padding
android:layout\u weight
组合的值。但是没有任何东西能给我想要的效果(即两个
TextView
占据相同的空间)


我远非Android XML专家,因此任何指针都将受到极大的赞赏。

我建议使用线性布局

<LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:weightSum="1.0"
     android:orientation="horizontal">
<TextView
     android:id="@+id/tvDate"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="0.5"
     android:background="#CCCCCC"
     android:gravity="center_vertical|center_horizontal"
     android:paddingRight="4dp"
     android:textColor="#000000" />
<TextView
     android:id="@+id/tvTime"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="0.5"
     android:background="#CCCCCC"
     android:gravity="center_vertical|center_horizontal"
     android:paddingLeft="4dp"
     android:textColor="#000000" />
</LinearLayout>

<LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:weightSum="1.0"
     android:orientation="horizontal">
<Button
     android:id="@+id/buttonDate"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="0.5"
     android:gravity="center_vertical|center_horizontal"
     android:paddingRight="4dp"
     android:text="Pick Date" />
<Button
     android:id="@+id/buttonTime"
     android:layout_width="0dp"
     android:layout_height="wrap_content"
     android:layout_weight="0.5"
     android:gravity="center_vertical|center_horizontal"
     android:paddingLeft="4dp"
     android:text="Pick Time" />
</LinearLayout>


我认为还有android:weight。。。检查文档。这应该可以解决问题。我目前使用的是
android:layout_-weight
在评论之前你有没有费心检查我的问题?如果只有两行,我建议使用两个水平线性布局,两个孩子的权重相等。我检查了你的问题,但我说了权重,这与layou-weight不同。。。下面的答案是。。。我忘记了总数,但这就是为什么我只是提供了一个评论,而不是一个答案。我猜下一次,我不会再遇到麻烦了。我在回复之前也检查了文档中提到的“权重”属性,除了我已经在使用“权重总和”的TextView小部件的“布局权重”属性之外,我没有找到任何东西。也许如果你加入一个链接,我就能理解你的干预。