首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓系统中的TextView滚动和动画

安卓系统中的TextView滚动和动画
EN

Stack Overflow用户
提问于 2010-09-27 03:21:15
回答 2查看 4.6K关注 0票数 2

我已经成功地启用了Android TextView的滚动功能,方法是将其放在ScrollView中,或者使用TextView的setMovementMethod (例如,myTextView.setMovementMethod(new ScrollingMovementMethod( ) );)。

不过,理想情况下,我希望看到TextView的滚动效果类似于IPhone/IPod touch的滚动效果,即文字会超调并反弹回来。在模拟器中,TextView只是滚动到开头或结尾,没有任何动画效果。

有没有一种简单的方法来启用这种滚动行为,或者使用安卓的动画功能和OvershootInterpolator的其他方法?

EN

回答 2

Stack Overflow用户

发布于 2013-08-08 05:40:52

听起来默认的ListView行为可能就是您想要的。在可扩展标记语言中定义ListView,然后设置一个在TextView中馈送的自定义适配器。

代码语言:javascript
复制
<ListView android:id="@+id/ListView01" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"/>

ListView文档:http://developer.android.com/reference/android/widget/ListView.html

您可以看到有一个OnOverScrolled方法。默认情况下,它应该可以工作。

票数 0
EN

Stack Overflow用户

发布于 2016-01-09 14:40:38

对于完整的TextView滚动,我们可以将#franta指定的代码编辑为以下代码

代码语言:javascript
复制
private void animateTextView() {
    int textWidth = getTextViewWidth(txtLastLocation);
    int displayWidth = Device.getDisplayWidth(getContext());

    if((displayWidth)<=textWidth) {
        textViewAnimation = new TranslateAnimation(
                textWidth, -textWidth,
                0, 0);
        textViewAnimation.setDuration(10000); // Set custom duration.
        textViewAnimation.setStartOffset(0);// Set custom offset.
        textViewAnimation.setRepeatMode(Animation.RESTART); // This will animate text back ater it reaches end.
        textViewAnimation.setRepeatCount(Animation.INFINITE); // Infinite animation.

        mTextView.startAnimation(textViewAnimation);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3799406

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档