安卓:在TextView中自动滚动文本 [英] Android: Auto-scrolling text in TextView

查看:196
本文介绍了安卓:在TextView中自动滚动文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一系列有100px的固定宽度的标签。制表包含与下面的一些文本的图像。如果文本太长,我希望它会自动滚动。我只想要一行。我尝试以下,但没有奏效。我使用的是Android 2.3:

I've created a series of tabs that have a fixed width of 100px. A tab contains an image with some text below it. If the text is too long to fit, I want it to automatically scroll. I only want one line. I tried the following but it did not work. I am using 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>

任何想法,为什么不工作?我碰到的解决方案,从另一个发布有用户表示,它的工作原理。

Any idea why this does not work? I came across the solution from another posting and there the user indicated that it works.

推荐答案

在你的活动,你必须,如果你想字幕的文本添加

In your activity you have to add if you want to marquee on text

  TextView tv=(TextView)findViewById(R.id.textview1);
  tv.setSelected(true);

这篇关于安卓:在TextView中自动滚动文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆