android问题:Textview选框无效

时间:2017-08-22 07:59:28

标签: android

我的xml部分是:

<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(true)。但仍然没有工作。

我正在使用Android Studio 2.3 ..

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

在您的代码中使用此行:

android:singleLine="true"

并从代码中删除此行:

android:lines="1"

希望这会帮助你。

答案 1 :(得分:0)

自API级别3以来,

android:singleLine属性已被弃用,您可以使用

android:maxLines="1"

使用Java可以使用

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