2

I am doing an application in which I have a textview and an image view inside a LinearLayout. Touching the linear layout takes us to another activity. As the text wont fit inside the textview, I want to make the textview content marquee. I have tried may methods but it is not working. The xml content is given below.

<LinearLayout
    android:id="@+id/profile_pic_Layout"
    android:layout_width="fill_parent"
    android:layout_height="100dip"
    android:layout_margin="10dip"
    android:background="@color/blue_background" >

    <ImageView
        android:id="@+id/profile_pic_menu"
        android:layout_width="100dip"
        android:layout_height="100dip"
        android:contentDescription="@string/image"
        android:scaleType="centerCrop" />

    <TextView
        android:id="@+id/profile_name_text"
        android:layout_width="fill_parent"
        android:layout_height="30dip"
        android:layout_gravity="bottom"
        android:gravity="center"
        android:marqueeRepeatLimit="1"
        android:inputType="text"
        android:lines="1"
        android:duplicateParentState="true"
        android:scrollHorizontally="true"
        android:fadingEdge="horizontal"
        android:focusable="true"
        android:textColor="@android:color/white"
        android:textSize="20sp">
        <requestFocus android:focusable="true" 
            android:focusableInTouchMode="true"
            android:duplicateParentState="true"  /> 
    </TextView>
</LinearLayout>

I have also tried setting the textview selected in the code by using,

profileNameTextView.setEllipsize(TruncateAt.MARQUEE);
profileNameTextView.setSelected(true);

I think the it is because, the the parent linearlayout is having the focus. Please help me fix this issue..!

Thank you all in advance..!

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Aswathy P Krishnan
  • 11,728
  • 7
  • 27
  • 45

2 Answers2

1

Apparently you are missing the android:ellipsize="marquee" attribute

Here's a minimalistic working example:

   <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:marqueeRepeatLimit="1"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:text="HELLO HOW ARE YOU WHAT ARE YOU DOING TEST ANDROID IS WRITING TO YOU." />
Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • Sorry!, but I ahd tried that from the xml first. But I moved it to code using profiletextView.setEllipsize(TruncateAt.MARQUEE); while trying out other methods. It was not working out. Any idea what to do when the container layout is having the focus? I tried setting duplicate parentstate also. I found another method in this link http://stackoverflow.com/questions/4474178/how-to-activate-a-marquee-for-a-textview-inside-a-focused-viewgroup , but I dont want to create a class for that! – Aswathy P Krishnan Aug 24 '12 at 14:10
1
public class TextViewMarquee extends Activity {
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv = (TextView) this.findViewById(R.id.mywidget);  
    tv.setSelected(true);  // Set focus to the textview
}
}

The xml file with the textview:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
    android:id="@+id/mywidget"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:lines="1"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:textColor="#ff4500"
    android:text="Simple application that shows how to use marquee, with a long text" />

Sampath Kumar
  • 4,433
  • 2
  • 27
  • 42