1

I have a textview Which Contains some text changes dynamically within the UI like below

layout:

<TableRow android:weightSum="2" >

            <ImageButton
                android:id="@+id/archive"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="90dp"
                android:background="@drawable/archive" />

            <ImageButton
                android:id="@+id/facebook"
                android:layout_width="-200dp"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:background="@drawable/facebook" />
        </TableRow>

        <TableRow android:layout_marginTop="2dp" >

            <TextView
                android:id="@+id/titlename1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="4dp"
                android:text="@string/nowplaying"
                android:textColor="#000000"
                android:textSize="12sp"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/titlename"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="4dp"
                android:layout_weight="1"
                android:ellipsize="none"
                android:gravity="right"
                android:maxEms="25"
                android:maxLines="1"
                android:scrollHorizontally="false"
                android:textColor="#000000"
                android:textSize="11dp" />
        </TableRow>

        <TableRow android:layout_marginTop="2dp" >

            <FrameLayout
                android:id="@+id/mainlayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginLeft="0dp"
                android:orientation="vertical" >

                <ImageButton
                    android:id="@+id/playbtn"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:background="@drawable/play" />

                <ImageButton
                    android:id="@+id/pausebtn"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:background="@drawable/pause" />
            </FrameLayout>

            <SeekBar
                android:id="@+id/seekBar1"
                android:layout_width="500dp"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/mainlayout"
                android:layout_marginLeft="-203dp"
                android:layout_marginRight="0dp" />
        </TableRow>

My Problem is that when i execute my Program,my layout output:

Imagebutton1     ImageButton2

NowPlaying:    SongDetails

Play/Pause      SeekBar

Problem is If my SongDetails text lenght Contains 2 or 3 lines My layout is getting Disturbed?Could any one Suggest?My Requirement is to limit the text like

Song Detailssss etc......in a Same Row

Renjith
  • 5,783
  • 9
  • 31
  • 42
String
  • 3,660
  • 10
  • 43
  • 66

5 Answers5

4

Simply use android:singleLine="true", and android:ellipsize="end". So You need to update TextView code as

<TextView
                .....
....
                android:ellipsize="end"
               android:singleLine="true" />

Refrences :

  1. android:singleLine
  2. android:ellipsize
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
1

try to use

android:singleLine="true"

in your textview

also you can set marquee.

Note that this marquee will work if your text line is longer then your screen size only.

Community
  • 1
  • 1
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
1

Try setting android:ellipsize paremeter to "end"

Like this

android:ellipsize="end"
CRUSADER
  • 5,486
  • 3
  • 28
  • 64
0

Try setting android:ellipsize paremeter to "end" if you want to trim the content at the end.

android:ellipsize="end"
ajaykoppisetty
  • 364
  • 4
  • 10
-1

Just remove wrap_content. That should work(haven't tried it myself recently, but I used it a couple of months ago).

Otherwise, you could cut the text manually in Java, and cut it at the first newline found.

Anickyan
  • 404
  • 2
  • 10