简体   繁体   中英

How can I stop the text on my buttons spanning over 2 lines?

I've got 5 buttons in a horizontal linear layout, the last one can't fit on the screen so its broken into two lines such as :

Ita
lian

Instead of Italian

Is there anyway I can force it to not do this? Is there a dynamic way, in such a case of a smaller device where it may only fit 2 buttons side by side that it could drop the next down to the next row? Maybe something like the following :

English German 
Italian Spanish
French

This is my main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/prompt"
            />
    <EditText
            android:id="@+id/inputText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="horizontal"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
            >
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/speakEnglish"
                android:onClick="speakEnglish"/>
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/speakSpanish"
                android:onClick="speakSpanish"/>
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/speakFrench"
                android:onClick="speakFrench"/>
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/speakGerman"
                android:onClick="speakGerman"/>
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/speakItalian"
                android:onClick="speakItalian"/>
    </LinearLayout>
</LinearLayout>

还没有尝试过,但是尝试给它一个固定的高度和singleLine="true"

或者试试这个android:maxLines =“ 1”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM