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.

2
  • use android:margin_fromRight for your textview and set a margin so it won't overlap with imageview Commented Jul 31, 2014 at 5:33
  • Thanks to all for your responses. android:layout_toLeftOf="@+id/btnSettings" is working.Cheers Commented Jul 31, 2014 at 5:54

6 Answers 6

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"/>
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

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.

Comments

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>

Comments

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>

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.