android - 将 LinearLayout 内的按钮高度与水平方向相匹配

标签 android android-layout

我遇到了一个棘手的情况,我似乎无法理解。我有一个 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>

现在,我的表单看起来基本正确。但问题是该按钮在垂直方向上比文本字段高,因此它将表单中的行推得比我想要的更远。 (我不能发截图,因为我刚加入,声望值不够。呵呵。)

我一直在谷歌搜索各地试图找到解决方案,但我似乎无法弄清楚。这一定是一些简单的事情,但我已经用头撞 table 有一段时间了:)

有什么建议吗?非常感谢!

最佳答案

如果没有为每个元素实际设置相同的高度,我认为它们不会具有完全相同的高度。

但是您可以做的一件事是将按钮的最小高度设置为零,这很可能会解决按钮拉伸(stretch)整条线的问题。

通过在按钮内使用 android:minHeight="0px" 来实现此目的。

关于android - 将 LinearLayout 内的按钮高度与水平方向相匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29112218/

相关文章:

android - 如何制作轮式拾取器

android - FragmentManager 非法状态异常 : No host

c# - 在 xamarin for android 中更改字体时出错

android - 框架布局 : Fill empty space

java - 从字符串中删除最后一个字符

Android In App Billing v3 不适用于 Nexus 7

Android 线性/相对布局 - 如何将 "auto size"对象放在中间(3 个对象)

java - Android:使用 setBackgroundDrawable 设置后位图变小

android - Leak Canary - 未显示 libgdx 应用程序的引用堆栈

android - Flutter:如何在 Flutter 中使图像的某些区域透明?