Reputation: 3891
I've got an xml file for a ListView item. it looks like this, containing three textviews:
Now, the second TextView in the middle sometimes got text that is too long to fit between the other two TextViews. That's why I wanted to make it ellipsized.
My .xml file looks like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="2dp"
android:background="@drawable/card_background" >
<TextView
android:id="@+id/list_textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="@string/test"
android:textColor="@color/text"
android:textSize="20sp"
android:textStyle="bold"
android:width="75dp" />
<TextView
android:id="@+id/list_textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_toRightOf="@+id/list_textview1"
android:layout_toLeftOf="@+id/list_textview3"
android:text="@string/test"
android:textColor="@color/text"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/list_textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="20dp"
android:paddingRight="5dp"
android:text="@string/test"
android:textColor="#DEDEDE"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
As You might see in the center TextView values, I've added
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
But the result is just a long text, shorten with three points at the end. It just won't move?
Here's an image:
This center TextView does not scroll. Note that it's an item of a ListView. That's why I tried to made the center TextView focusable, what ended in not being able to press on the list item.
Any ideas?
Upvotes: 1
Views: 590
Reputation: 3891
I've got the solution from user zgc7009 :
I just had to add:
TextView textView3 = (TextView) findViewById(R.id.list_textview3);
textView3.setSelected(true);
Worked nicely, thanks!
Upvotes: 1