android - 带有多行文本的按钮下沉在对齐线下,如何解决?

标签 android layout button alignment multiline

我看到简单按钮的奇怪行为,当它们的文本分成几行时。我在更复杂的情况下遇到过它,但即使在最简单的情况下也会发生。使用这种布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111 222 333" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111 222 333 444 555 666" />
<Button android:layout_width="100dip" android:layout_height="70dip" android:text="111" />
</LinearLayout>

结果是:buttons not in a row

按钮随着文本的每一行而下降。我要他们排成一行。这是 Android 错误吗?如何修复?

最佳答案

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:layout_width="100dip"
            android:layout_height="70dip"
            android:layout_gravity="center"
            android:text="111" />

        <Button
            android:layout_width="100dip"
            android:layout_height="70dip"
            android:layout_gravity="center"
            android:text="111 222 333" />

        <Button
            android:layout_width="100dip"
            android:layout_height="70dip"
            android:layout_gravity="center"
            android:text="111 222 333 444 555 666" />

        <Button
            android:layout_width="100dip"
            android:layout_height="70dip"
            android:layout_gravity="center"
            android:text="111" />
    </LinearLayout>

</LinearLayout>

关于android - 带有多行文本的按钮下沉在对齐线下,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9129257/

相关文章:

java - 我的 "ACTION_MOVE"从未在我的 longPressListener 中调用

android - 指针事件 : "auto" in child element not reversing parents "none" on mobile

javascript - AAPT : No resource found that matches the given name: attr 'android:keyboardNavigationCluster'

html - 在行尾右对齐文本(不带表格)

Android - 获取 ListView 项目高度?

ios - 无法使用辅助指示器进行 segue

css - 单击关闭按钮时,我的 Bootstrap 警报框不会关闭

java - REST POST 请求不适用于 Java 但适用于 REST 客户端

Android相对布局居中垂直带边距

javascript - 在 IEAutomation 中单击按钮时如何让 Javascript 执行?