将 LinearLayout 内的按钮高度与水平方向匹配
Matching button height inside LinearLayout with Horizontal Orientation
我遇到了一个棘手的情况,我似乎无法解决问题。我有一个 Android 表格。我有三个元素,一个标签,一个文本字段(只读,因为它是由日期选择器设置的)和一个按钮。代码如下所示:
<!-- container: each row in the form stacks vertically -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip"
android:orientation="vertical" >
<!-- Here's the date picker element I'm trying to figure out -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10.0dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_label"
android:textColor="#ffffff"/>
<EditText
android:id="@+id/eventDate"
android:layout_width="0dp"
android:layout_weight="0.50"
android:layout_height="wrap_content"
android:inputType="date"
android:background="#ffffff"
android:focusable="false"
android:maxLines="1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_text"
/>
</LinearLayout>
</LinearLayout>
现在,我的表格看起来基本正确。但问题是按钮在垂直方向上比文本字段高,因此它会将表单中的行推得比我想要的更远。 (我不能post截图,因为我刚加入,没有足够的声望点。呵呵。)
我一直在到处谷歌搜索以尝试找到解决方案,但我似乎无法弄清楚。它必须是简单的东西,但我已经用头撞桌子了一段时间了:)
有什么建议吗?非常感谢!
尝试将 TextView
、EditText
和 Button
的 layout-height
设置为 match_parent
。
如果不为每个元素实际设置相同的高度,我认为它们不会具有完全相同的高度。
但是您可以做的一件事是将按钮的最小高度设置为零,这很可能会解决按钮拉伸整条线的问题。
使用按钮内的 android:minHeight="0px"
即可。
我遇到了一个棘手的情况,我似乎无法解决问题。我有一个 Android 表格。我有三个元素,一个标签,一个文本字段(只读,因为它是由日期选择器设置的)和一个按钮。代码如下所示:
<!-- container: each row in the form stacks vertically -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip"
android:orientation="vertical" >
<!-- Here's the date picker element I'm trying to figure out -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10.0dip" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_label"
android:textColor="#ffffff"/>
<EditText
android:id="@+id/eventDate"
android:layout_width="0dp"
android:layout_weight="0.50"
android:layout_height="wrap_content"
android:inputType="date"
android:background="#ffffff"
android:focusable="false"
android:maxLines="1" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="@string/set_date_text"
/>
</LinearLayout>
</LinearLayout>
现在,我的表格看起来基本正确。但问题是按钮在垂直方向上比文本字段高,因此它会将表单中的行推得比我想要的更远。 (我不能post截图,因为我刚加入,没有足够的声望点。呵呵。)
我一直在到处谷歌搜索以尝试找到解决方案,但我似乎无法弄清楚。它必须是简单的东西,但我已经用头撞桌子了一段时间了:)
有什么建议吗?非常感谢!
尝试将 TextView
、EditText
和 Button
的 layout-height
设置为 match_parent
。
如果不为每个元素实际设置相同的高度,我认为它们不会具有完全相同的高度。
但是您可以做的一件事是将按钮的最小高度设置为零,这很可能会解决按钮拉伸整条线的问题。
使用按钮内的 android:minHeight="0px"
即可。