【问题标题】:Android: how to layout the button so the text looks like the one in screenshot?Android:如何布局按钮以使文本看起来像屏幕截图中的文本?
【发布时间】:2011-09-03 05:39:27
【问题描述】:

请看上面的截图,文本的字符串是“DELETE SELECTED\nMESSAGES”,如果我使用 wrap_content 作为其父线性布局的宽度/高度,文本将如下所示:

删除

选择

消息

(每个单词之间没有行间距)

如果我使用 match-parent 作为按钮的宽度,它将被拉伸以匹配其父级,这不是我想要的。谁能帮我解决这个问题?

谢谢!

编辑:

按钮的布局:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_margin="5dip"
        android:paddingTop="5dip"
        android:paddingBottom="0dip"
        android:background="@drawable/solid_grey_btm_rounded">
        <Button
            android:text="@string/delete_selected_messages"
            android:id="@+id/btn_delete_message"
            android:gravity="center"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@drawable/button_grey_selector">
        </Button>
</LinearLayout>

我正在使用 Android 2.3.3 API Level 10,我正在摩托罗拉里程碑(带有真正键盘的那个)上进行测试

【问题讨论】:

  • 它对我有用。如果您说您使用的是哪个Android版本以及什么手机,也许会有所帮助
  • 也许你可以使用固定宽度..你可以发送你的布局代码吗?

标签: android layout text button alignment


【解决方案1】:

尝试使用android:minLines="2",这应该会有所帮助。

【讨论】:

  • 我试了一下,字符串中有换行符,仍然显示三行,如果我去掉换行符,就只是一行,拉长了按钮的宽度。
【解决方案2】:

我解决了这个问题,我将按钮的 layout_width 和 layout_height 设置为“match_parent”或“fill_parent”,还添加了边距以使按钮不填充其父级,添加了填充以使文本更窄。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多