2017-08-22 61 views
0

節我的XML是:Android的問題:TextView的字幕不工作

<RelativeLayout 
    android:id="@+id/headerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:background="@color/colorDeepGreen"> 

    <TextView 
     android:id="@+id/tvModelMakeYear" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:layout_margin="@dimen/margin_one" 
     android:textColor="#fff" 
     android:textSize="16dp" 
     android:ellipsize="marquee" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:lines="1" 
     android:scrollHorizontally="true" 
     android:focusable="true" 
     android:focusableInTouchMode="true"/> 

</RelativeLayout> 

我都內的onCreate添加tvModelMakeYear.setSelected(真)()。但仍然選框不起作用。

我正在使用Android Studio 2.3 ..

請幫我解決問題。

+1

添加tvModelMakeYear.setSingleLine(真);在tvModelMakeYear.setSelected(true)之後,這應該起作用。它不會在代碼中顯示棄用。 –

回答

0

使用這一行代碼:

android:singleLine="true" 

,並從代碼中刪除這一行:

android:lines="1" 

希望這將幫助你。因爲API等級3

+0

我已經試過this.But android:singleLine =「true」現在已棄用。所以我使用android:maxLines =「1」作爲替代方法。仍然有效的選取框不起作用:( – Abbul

+0

matquee僅適用於singleline屬性而不是線條屬性 –

0

android:singleLine屬性已被棄用,你可以使用

android:maxLines="1" 

使用Java,你可以像使用

TextView textBox = (TextView)findViewById(R.id.tvModelMakeYear); 
textBox.setMaxLines(1); 
+0

我已經在xml中使用了這個,但仍然跑馬燈不工作:( – Abbul

+0

android:focusable =「true」 android:focusableInTouchMode =「true」 –

+0

將這兩行添加到textview –