按钮不适合其文本

时间:2017-01-12 13:08:33

标签: android

我有一个带有两个按钮的LinearLayout。但是,当按钮具有需要断开的较长文本时,按钮的高度不会扩展以适合文本。相反,它会裁剪文本。

这就是我所拥有的:

<LinearLayout
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="2">

    <Button
        android:id="@+id/previous_button"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:text="@string/previous_button"
        android:textColor="@color/light_blue" />

    <Button
        android:id="@+id/next_button"
        style="?android:attr/buttonBarButtonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:text="@string/next_button"
        android:textColor="@color/light_blue" />

</LinearLayout>

有关为什么按钮裁剪文字的任何帮助?

Here's a screenshot of the layout

4 个答案:

答案 0 :(得分:0)

尝试将android:singleLine="false"属性添加到有问题的按钮。希望这能解决你的问题。

如果它不起作用,可能需要通过添加android:padding="0dp"来删除按钮的默认填充

答案 1 :(得分:0)

您可以使文本以多行对齐。 默认情况下,水平LinearLayout会对齐其所有子控件的基线。因此,多行按钮中的第一行文本与其他按钮中的单行文本垂直对齐。

要禁用此行为,请设置android:baselineAligned =&#34; false&#34;在LinearLayout上

例如,

<LinearLayout
            android:id="@+id/bottom_linear_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false"
            android:orientation="horizontal">

            <Button
                android:id="@+id/two_board_btn_continue"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/rounded_corner_blue_button"
                android:text="@string/continue_bidding"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/two_board_btn_checkOut"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/rounded_corner_blue_button"
                android:text="@string/checkout"
                android:textColor="@android:color/white" />

            <Button
                android:id="@+id/two_board_btn_cart"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="1"
                android:background="@drawable/rounded_corner_blue_button"
                android:text="@string/add_to_cart"
                android:textColor="@android:color/white" />

        </LinearLayout>

答案 2 :(得分:0)

只需从两个按钮中删除@style。

答案 3 :(得分:-1)

你的按钮名称多长。你已经使用了匹配父。因此,只有你可以减少Button的textSize。这就是全部。

相关问题