Denny Kurniawan
Denny Kurniawan

Reputation: 1915

How To make TableLayout same width and wrap content

i am try to make application when the TextView changed value, then the TableLayout and Text View will wrap content in one line text, table row below the first TableRow will follow the first TableRow width.

This is My Code xml :

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_height="wrap_content"
        android:layout_margin="10dp" >

        <!-- Column 1 -->
        <TextView
            android:id="@+id/textView1"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="I want This Layout in one line " />

        <!-- Column 2 -->
        <TextView
            android:id="@+id/textView2"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="This textview in one line" />

        <!-- Column 3 -->
        <TextView
            android:id="@+id/textView3"
            android:layout_height="wrap_content"
            android:layout_width="0dip"
            android:layout_weight="1"
            android:text="This to" />
    </TableRow>

    <!-- more rows
    <TableRow ... </TableRow>
    -->
</TableLayout>

My Layout

Thanks in advance

Upvotes: 1

Views: 1182

Answers (1)

sumit
sumit

Reputation: 1087

You need to add these two lines to your textview:

android:maxLines="1"
android:ellipsize="end"

that way when your text will be longer than what can be adjusted in one line it will ellip at end

and if you're using LinearLayout then a simple hack will be set your LinearLayout width to wrap_content then parent Layout width will become equal to biggest child. Then you can set the width of the small child to match_parent and it'll match the width of required view.

Upvotes: 2

Related Questions