kgandroid
kgandroid

Reputation: 5595

Android Textview not showing multiple lines within a list

May be this is a duplicate question,but I am asking it again because the solutions here is not working for me.I have a listview and within the list view I have 2 imageviews and a textview.Refer to the image below:

enter image description here

As you can see I cannot split the textviews into 2 lines and as a result my textview is overlapping with that of the imageview.Here is my code:

uplodefilelist.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_filelist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:paddingBottom="20dp"
    android:paddingTop="20dp" >

    <ImageView
        android:id="@+id/fileimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:src="@drawable/default_avatar" />

    <RelativeLayout
        android:id="@+id/ll_cntactcont"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@+id/fileimage" >

        <TextView
            android:id="@+id/tvfilename"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="Srina Banerjee"
            android:textColor="#000000"
            android:textStyle="bold"
            android:ellipsize="end"
            android:maxLines="2"
            android:singleLine="false"
           />

        <ImageView
            android:id="@+id/btnSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/settings"
            android:textColor="#000000"
            android:focusable="false"
            android:focusableInTouchMode="false" />
    </RelativeLayout>

</RelativeLayout>

I cannot use any html format within the setText() method or I cannot do anything from java file.I have to do it from within the xml file only.I consulted our very own stack overflow and added this lines in my textview.

android:ellipsize="end"
android:maxLines="2"
android:singleLine="false"

But as you can see the image none of them are working.Help.

Upvotes: 1

Views: 5664

Answers (6)

Pragnesh Ghoda  シ
Pragnesh Ghoda シ

Reputation: 8337

you just have to add one line to your TextView

android:layout_toLeftOf="@+id/btnSettings" 

Try this Code...

<ImageView
    android:id="@+id/fileimage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="10dp"
    android:src="@drawable/default_avatar" />

<RelativeLayout
    android:id="@+id/ll_cntactcont"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="5dp"
    android:layout_marginTop="10dp"
    android:layout_toRightOf="@+id/fileimage" >

    <TextView
        android:id="@+id/tvfilename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="Srina Banerjee "
        android:layout_toLeftOf="@+id/btnSettings" <!-- use this for setting  textview properly -->
        android:textColor="#000000"
        android:lines="2" <!-- put this line if you always want to show 2 lines -->
        android:textStyle="bold"
        android:maxLines="2" <!-- max number of size... used when text is long -->
       />

    <ImageView
        android:id="@+id/btnSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/settings"
        android:textColor="#000000"
        android:focusable="false"
        android:focusableInTouchMode="false" />
</RelativeLayout>

Upvotes: 1

Digvesh Patel
Digvesh Patel

Reputation: 6533

just add 1 tag in to Textview That

 android:layout_toLeftOf="@+id/btnSettings"

So this old one is

 <TextView
     android:id="@+id/tvfilename"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_centerVertical="true"
     android:text="Srina Banerjee"
     android:textColor="#000000"
     android:textStyle="bold"
     android:ellipsize="end"
     android:maxLines="2"
     android:singleLine="false"/>

Change to :

 <TextView
     android:id="@+id/tvfilename"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_centerVertical="true"
     android:text="Srina Banerjee"
     android:textColor="#000000"
     android:layout_toLeftOf="@+id/btnSettings"
     android:textStyle="bold"
     android:ellipsize="end"
     android:maxLines="2"
     android:singleLine="false"/>

Upvotes: 2

Kaushik
Kaushik

Reputation: 6162

Add android:layout_toLeftOf="@+id/btnSettings" in textview and remove its parent relative layout try this layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rl_filelist"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:paddingBottom="20dp"
    android:paddingTop="20dp" >

    <ImageView
        android:id="@+id/fileimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:src="@drawable/default_avatar" />

    <TextView
        android:id="@+id/tvfilename"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_toLeftOf="@+id/btnSettings"
        android:layout_toRightOf="@+id/fileimage"
        android:ellipsize="end"
        android:maxLines="2"
        android:singleLine="false"
        android:text="Srina Banerjee"
        android:textColor="#000000"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/btnSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:src="@drawable/settings"
        android:textColor="#000000" />

</RelativeLayout>

Upvotes: 1

Giru Bhai
Giru Bhai

Reputation: 14398

add android:layout_toLeftOf="@+id/btnSettings" in your textview as

<TextView
            android:id="@+id/tvfilename"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="Srina Banerjee"
            android:textColor="#000000"
            android:textStyle="bold"
            android:ellipsize="end"
            android:maxLines="2"
            android:singleLine="false"
            android:layout_toLeftOf="@+id/btnSettings"
           />

And don't forget to clear the project.

Upvotes: 1

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

Try this way,hope this will help you to solve your problem.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:gravity="center">

    <ImageView
        android:id="@+id/fileimage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:adjustViewBounds="true"/>

    <LinearLayout
        android:id="@+id/ll_cntactcont"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp">
        <TextView
            android:id="@+id/tvfilename"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Srina Banerjee"
            android:textColor="#000000"
            android:textStyle="bold"
            android:ellipsize="end"
            android:maxLines="2"/>
    </LinearLayout>

    <ImageView
        android:id="@+id/btnSettings"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher"
        android:textColor="#000000"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_marginLeft="5dp"/>

</LinearLayout>

Upvotes: 1

chr1st3nd0
chr1st3nd0

Reputation: 44

Your textview needs to be a specific width for it to wrap not wrap content. You probably want to do a LinearLayout and not Relative for those 3 views.

Upvotes: 0

Related Questions