简体   繁体   中英

Android Text is wrapped in button - why?

I have the following XML:

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/verylongtext" android:layout_weight="1000" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sometext" android:onClick="onClickButton" android:layout_weight="1" />

</LinearLayout>

Though I have set a layout_weight there is still a linebreak in the text on the button, the button should show

sometext

but it shows

somet

ext

Why is this and how can I fix it?

Thanks!

Include android:singleLine="true" to Button xml.

You don't specify the orientation of your LinearLayout , so it is defaulting to horizontal. The TextView is squeezing the Button . Also, when you use android:layout_weight , then you often don't want to constrain the objects in the layout in the relevant dimension, so you can put " 0px " instead of " wrap_content " or " match_parent " and let the weight determine the respective proportional sizes.

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