selva
selva

Reputation: 444

Android Textview moves other views out of the layout

In my layout I need to have a textview with two buttons next to that and one cancel button at right side (refer below image)enter image description here

But when the text view is too long then the buttons near to the textview goes behind the cancel button(refer the below image) enter image description here

Attached xml file for your reference,

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content" android:layout_weight="1">
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World, MActivity"
            android:singleLine="true"
            android:paddingTop="10dp"
            android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"
            android:ellipsize="end"/>
    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="yes" />
    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="no" />
</LinearLayout>
    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="cancel" />
</LinearLayout>

Upvotes: 0

Views: 290

Answers (1)

Derek Fung
Derek Fung

Reputation: 8211

This question has been asked multiple times, but there should have no basic layout solution to handle this. You have to write custom code to completely solve this problem.

You can use a workaround, set android:maxWidth for TextView

e.g.

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="150dp"/>

Upvotes: 1

Related Questions