0

I am implementing listview with 2 textviews , and for reference used Basic Layout and Formatting

Instead of stock names which are short i am using long text, so when i use a long text, it overlaps with the second .

So how to get it right, so that the 2 textviews don't overlap each other.

Hitesh Patel
  • 2,868
  • 2
  • 33
  • 62

3 Answers3

0

To avoid overlapping, you could set the second textview to align to right (android:layout_toRightOf).

For example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"
        android:layout_alignParentLeft="true" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_price"
        android:layout_toRightOf="@id/ticker_symbol"
        android:layout_alignParentRight="true"  />
</RelativeLayout>
Stelian Matei
  • 11,553
  • 2
  • 25
  • 29
  • yes , it does that in the example , but it still overlaps one textview over the other , my 2nd textview doesn't shift at all , and first textview overlaps with it – user1455192 Jun 21 '12 at 14:00
  • The line `android:layout_toRightOf="@id/ticker_symbol"` was added by me. It was not in the original example. Can you please add the XML code you are using so we can discuss on it? – Stelian Matei Jun 21 '12 at 14:01
  • You could also use the `android:weight` attribute to set the width to 50% for each textview instead of `wrap_content`. Check out this http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout – Stelian Matei Jun 21 '12 at 14:03
  • the xml file is same which you posted above – user1455192 Jun 21 '12 at 14:05
  • again ,same as above , in relative layout i can't use android:weight – user1455192 Jun 21 '12 at 14:09
  • Maybe you could create a new `LinearLayout` inside the `RelativeLayout` containing the textviews and you can use android:weight. You can still keep RelativeLayout as the parent layout, if you need it for other eventual elements. What do you think? – Stelian Matei Jun 21 '12 at 14:15
0

You can used following code to solve your problem:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1">
    <TextView
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"

         android:text="sdasd sadas"
         android:layout_weight=".5"/>
    <TextView
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_price"
         android:text="dfsd"
         android:layout_weight=".5"
         android:gravity="right" />
</LinearLayout>

Output:

Output of Code

Hitesh Patel
  • 2,868
  • 2
  • 33
  • 62
Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
0

I guess you mean due to long length of text it goes to next line or on next TextView

So i suggest you to use textView property android:ellipsized="end" and also use android:single_line="true" instead this you can directly specify the maxline=1 I'm not sure with names spelled correctly so check while typing

<TextView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:id="@+id/ticker_symbol"
        android:ellipsezed="end"
        android:singe_line="true"  
        android:layout_alignParentLeft="true" />

Hope this explanation woks for you let me know..

MobileEvangelist
  • 2,583
  • 1
  • 25
  • 36