1

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.

Community
  • 1
  • 1
kgandroid
  • 5,507
  • 5
  • 39
  • 69

6 Answers6

2

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"/>
Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40
Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34
1

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.

Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
1

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>
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
1

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>
Kaushik
  • 6,150
  • 5
  • 39
  • 54
1

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>

Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40
0

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.

chr1st3nd0
  • 44
  • 3