在Android中滚动textview不滚动。
我正在将文本滚动为here。在Android中滚动textview不滚动。
我想我看到它是第一次在另一个布局中滚动,即使没有任何Java代码。 但现在,它不再滚动了。不知道这有什么问题。
<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>
只是把这些线在你的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"
并在代码:
textView.setSelected(true);
虽然setSelected(true)不需要,但它工作正常。 –
感谢这些信息,我从来没有尝试过没有它... – Bhavnik
添加该代码在活动
TexView tv=findViewbyId(R.id.scrollingText);
tv.setSelected(true);
它不起作用。当我将singleLine更改为maxLines =“1”时,它正在工作 –
它现在滚动。我只是将maxLines="1"
更改为singleLine="true"
,你知道这有点奇怪。我将singleLine
更改为maxLines
,因为IDE建议我使用maxLines
而不是singleLine
,因为它已被弃用。
是的,singleLine即使已被弃用也可用于选取框,根据文档maxLines使textLines与我们提供的高度相当,而singleLine表示将文本约束为单个水平滚动线,而不是让它包装成多行 – Bhavnik
设置布局宽度android:layout_width =“wrap_content”,然后尝试 – Pavya
完成。一样。仍然不滚动。 –
尝试在代码中使用'textView.setSelected(true)'。来源:[链接](http://*.com/a/3333855/5373110) – Meet