Shahbaz Pothiawala
Shahbaz Pothiawala

Reputation: 1215

Android TextView Overflow

I am creating sort of an image gallery (with view flipper) wherein each view of viewflipper has an imageview and two textviews below it. What I want is to adjust the width of these textviews accoring to the imageviews width. These imageview and text are added dynamically to viewflipper so cannot adjust width in xml. Also the width of images is different everytime( some portrait, some landscape). Googleing did not help. So here is what I want. Any help would be appreciated.enter image description here

Upvotes: 1

Views: 3670

Answers (2)

user2496783
user2496783

Reputation: 101

Try like this, it may help you

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:src="your image" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView"
        android:layout_alignRight="@+id/imageView"
        android:layout_below="@+id/imageView"
        android:layout_marginTop="16dp"
        android:text="I am creating sort of an image gallery (with view flipper) wherein each view of viewflipper has an imageview and two textviews below it. " />

</RelativeLayout>

Upvotes: 5

Vaibs_Cool
Vaibs_Cool

Reputation: 6160

Try This

tv.setMaxLines(2);
tv.setEllipsize(TextUtils.TruncateAt.END);

More Documentation : http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize

Upvotes: 2

Related Questions