0

I'm making my text scrolling as the post here.

I think I saw it was scrolling first time in another layout even without any java code. But now, it's not scrolling anymore. No idea what's wrong with this.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?attr/actionBarSize">

    <LinearLayout
        android:id="@+id/scrollingTextLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="#0792B5"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/scrollingText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:maxLines="1"
            android:padding="5dp"
            android:scrollHorizontally="true"
            android:text="The culture of India is the way of living of people of India."
            android:textColor="#FFFFFF"
            android:textSize="16sp" />

    </LinearLayout>

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/scrollingTextLayout"
        android:background="@android:color/darker_gray" />

</RelativeLayout>
Community
  • 1
  • 1
Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54
  • set layout width android:layout_width="wrap_content" and then try – Pavya Dec 15 '16 at 08:17
  • Done. The same. Still not scrolling. – Zin Win Htet Dec 15 '16 at 08:21
  • Try with `textView.setSelected(true)` in your code. Source: [link](http://stackoverflow.com/a/3333855/5373110) – Meet Vora Dec 15 '16 at 08:25
  • Please try and add this: android:singleLine="true" to you textview in the XML and try and set focus on the TextView in onCreateView() or whenever you need the marquee to start scrolling. – Gilad Eshkoli Dec 15 '16 at 08:26
  • It's now scrolling. I just changed maxLines="1" to singleLine="true" , you know it's a little weird. I changed singleLine to maxLines="1" because the IDE suggested me to use maxLines instead of singleLine since it's deprecated already. – Zin Win Htet Dec 15 '16 at 08:31

3 Answers3

1

just put these lines in your xml:

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:scrollHorizontally="true"

And in your code:

textView.setSelected(true);
Bhavnik
  • 2,020
  • 14
  • 21
1

It's now scrolling. I just changed maxLines="1" to singleLine="true" , you know it's a little weird. I changed singleLine to maxLines because the IDE suggested me to use maxLines instead of singleLine since it's deprecated already.

Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54
  • 1
    Yes, singleLine is working for marquee even though it is deprecated, according to document maxLines makes the textLines as many tall as we've given, while singleLine means Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines – Bhavnik Dec 15 '16 at 10:02
0

Add this code in Activity

TexView tv=findViewbyId(R.id.scrollingText);
tv.setSelected(true);
noobEinstien
  • 3,147
  • 4
  • 24
  • 42