Android:在TextView中自动滚动文本

And*_*Dev 5 android scroll textview

我创建了一系列固定宽度为100px的标签.选项卡包含一个图像,其下方有一些文本.如果文本太长而不适合,我希望它自动滚动.我只想要一条线.我试过以下但是没有用.我使用的是Android 2.3:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginRight="3dp"
    android:layout_marginTop="3dp"
    android:background="#ff737373"
    android:gravity="center"
    android:minWidth="64dp"
    android:orientation="vertical"
    android:padding="3dp" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:tag="tabImage" >
    </ImageView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:maxWidth="100px"
        android:tag="tabCaption"
        android:textColor="#ffd9d9d9"
        android:textSize="16sp" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

知道为什么这不起作用吗?我从另一个帖子中看到了解决方案,用户表示它可以工作.

Kha*_*han 11

在您的活动中,如果要对文本进行选取,则必须添加

  TextView tv=(TextView)findViewById(R.id.textview1);
  tv.setSelected(true);
Run Code Online (Sandbox Code Playgroud)