Search code examples
androidandroid-layoutscrolltextviewmarquee

how to make a textview marquee inside a focussed layout in android


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..!


Solution

  • 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." />