Android platform using layout_weight, layout_width and maxWidth

I am trying to get a line of text that will be something like

foofoofoo - barbarbar

but I want it to be an ellipse of foo and bar, if it does not fit on one line. those. I try to cut them.

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/text_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:maxWidth="0dip"
        android:layout_weight="1"
        android:textColor="#ffffff"
        android:singleLine="true"
        android:ellipsize="true"
        android:text="foofoofoofoo" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:text=" - " />
    <TextView
        android:id="@+id/text_2"
        android:layout_width="wrap_content"                         
        android:layout_height="wrap_content"
        android:maxWidth="0dip"
        android:layout_weight="1"
        android:textColor="#ffffff"
        android:singleLine="true"
        android:ellipsize="true"
        android:text="barbarbarbar" />
</LinearLayout>

Follow me, it works partially.

Setting TextView layout_widthon 0dipand layout_weighton 1means that they will occupy 50% of the available space each.

Setting it singleLineto trueand ellipsizeto truemeans that they will look like foofoo ... if the text is larger than the container.

So my result (if the text is longer) should be

foofoo .. - barbar ..

What it is! So it works.

, ,, TextView (id: text_1) , 50%, layout_width="0dip" layout_weight="1" , wrap_content. :

foo - barbar..

foo - barbarbar

layout_width="wrap_content" android:maxWidth="0dip", ! , , wrap_content 50%!

, android:adjustViewBounds="true" maxWidth, .

+5
2

, , , , .

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="0,2"
    android:stretchColumns="0,2">
    <TableRow>
        <TextView android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:ellipsize="end"
            android:text="foofoofoo"/>
        <TextView android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="-"
            android:gravity="center_horizontal"/>
        <TextView android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:ellipsize="end"
            android:text="barbarbarbarbarbarbarbarbarbarbarbar"/>
    </TableRow>
</TableLayout>
+10

, , , , , . , -.

-, , , .

-, , , .

, . , -, .

+2

All Articles