在Android工作室中,带有多行文本的按钮在下方稍微移位

时间:2018-03-13 12:56:53

标签: android android-studio android-button

我希望在button上使用多行文字,但多重衬里使其略微向下移动 如何解决?

Buttons

以下是Button的XML代码: -

<TableLayout
    android:id="@+id/tab_buttons"
    android:layout_width="368dp"
    android:layout_alignParentTop="true"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="0dp"
    tools:layout_editor_absoluteX="8dp">
    <TableRow>
    <Button
        android:id="@+id/clock"
        android:background="#BAFFBA"
        android:text="@string/clock" />
    <Button
        android:id="@+id/Alarm"
        android:text="@string/Alarm"
        android:background="#004819"
        android:textColor="#FFFFFF"
        />
        <Button
            android:id="@+id/stopwatch"
            android:background="#BAFFBA"
            android:text="@string/Stopwatch" />
        <Button
            android:id="@+id/timer"
            android:background="#BAFFBA"
            android:text="@string/Timer" />
    </TableRow>
</TableLayout>

这是string秒表: -

<string name="Stopwatch">Stop&#10;Watch</string>

2 个答案:

答案 0 :(得分:1)

<LinearLayout
    android:id="@+id/tab_buttons"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <Button
        android:background="#BAFFBA"
        android:id="@+id/clock"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:text="@string/clock" />

    <Button
        android:background="#004819"
        android:id="@+id/Alarm"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:text="@string/Alarm"
        android:textColor="#FFFFFF" />

    <Button
        android:background="#BAFFBA"
        android:id="@+id/stopwatch"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:text="@string/Stopwatch" />

    <Button
        android:background="#BAFFBA"
        android:id="@+id/timer"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:text="@string/Timer" />
</LinearLayout>

答案 1 :(得分:1)

<TableLayout android:id="@+id/tab_buttons"
    android:layout_width="368dp"
    android:layout_alignParentTop="true"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteY="0dp"
    tools:layout_editor_absoluteX="8dp"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <TableRow>
        <Button
            android:id="@+id/clock"
            android:background="#BAFFBA"
            android:text="CLOCK" />
        <Button
            android:id="@+id/Alarm"
            android:text="ALARM"
            android:background="#004819"
            android:textColor="#FFFFFF"
            />
        <Button
            android:id="@+id/stopwatch"
            android:background="#BAFFBA"
            android:layout_height="match_parent"
            android:text="Stop&#10;Watch" />
        <Button
            android:id="@+id/timer"
            android:background="#BAFFBA"
            android:text="TIMER" />
    </TableRow>
</TableLayout>

只需将android:layout_height="match_parent"应用于秒表按钮。