2016-12-15 115 views
0

我正在將文本滾動爲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> 
+0

設置佈局寬度android:layout_width =「wrap_content」,然後嘗試 – Pavya

+0

完成。一樣。仍然不滾動。 –

+0

嘗試在代碼中使用'textView.setSelected(true)'。來源:[鏈接](http://stackoverflow.com/a/3333855/5373110) – Meet

回答

1

只是把這些線在你的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); 
+1

雖然setSelected(true)不需要,但它工作正常。 –

+1

感謝這些信息,我從來沒有嘗試過沒有它... – Bhavnik

0

添加該代碼在活動

TexView tv=findViewbyId(R.id.scrollingText); 
tv.setSelected(true); 
+0

它不起作用。當我將singleLine更改爲maxLines =「1」時,它正在工作 –

1

它現在滾動。我只是將maxLines="1"更改爲singleLine="true",你知道這有點奇怪。我將singleLine更改爲maxLines,因爲IDE建議我使用maxLines而不是singleLine,因爲它已被棄用。

+1

是的,singleLine即使已被棄用也可用於選取框,根據文檔maxLines使textLines與我們提供的高度相當,而singleLine表示將文本約束爲單個水平滾動線,而不是讓它包裝成多行 – Bhavnik