【问题标题】:Android Animations similar to make marquee verticalAndroid动画类似于使选框垂直
【发布时间】:2014-11-02 01:52:15
【问题描述】:

抱歉这个基本问题,因为我是 Android 新手:

我可以让我的TextView 在一行上水平滚动。

但我需要的是多个TextViews,它们以选取框的方式全部垂直滚动到屏幕底部,然后返回到顶部。

我已经搜索了几个小时,但在 android API 中看不到任何似乎可以做到这一点的东西。

或者有没有动画功能可以做到这一点?

【问题讨论】:

    标签: android android-layout android-animation textview marquee


    【解决方案1】:

    参考这个GitHub Project 它也有一个很好的例子。

    编辑: 让你的 xml 变成这样:

    <com.package.project.VerticalMarqueeTextView
    android:id="@+id/vmTextView"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/vmtvText"
    android:minLines="1"
    android:maxLines="10"
    android:width="250dp"
    android:textColor="@android:color/white"
    android:textStyle="bold" />
    

    在你的活动课上:

    private VerticalMarqueeTextView _txtView1; //declare a member variable
    

    onCreate():

    _txtView1 = (VerticalMarqueeTextView) findViewById(R.id.mTextView1);
    _txtView1.setMovementMethod(new ScrollingMovementMethod());
    

    在其他活动生命周期方法中:

    @Override
    protected void onResume() {
    
        // Start or restart the Marquee if paused.
        if (_txtView1.isPaused()) {
            _txtView1.resumeMarquee();
        }
        super.onResume();
    }
    
    @Override
    protected void onPause() {
    
        // Pause the Marquee when the Activity pauses.
        _txtView1.pauseMarquee();
        super.onPause();
    }
    
    @Override
    protected void onDestroy() {
    
        _txtView1.stopMarquee();
        super.onDestroy();
    }
    

    【讨论】:

    • 谢谢,我试过了,但它仍然在一行上水平滚动,而不是垂直向下滚动到屏幕底部。
    • 我已经更新了我的答案,看看那个例子,你只需要将那个类添加到你的项目中,像他们定义的那样定义文本视图,在onCreate() 中只需VerticalMarqueeTextView _textview1 = (VerticalMarqueeTextView) findViewById(R.id.vmTextView); _textview1.setMovementMethod(new ScrollingMovementMethod()); ,你可以使用stopMarquee()pauseMarquee()resumeMarquee()
    • 谢谢,所以我只需要将 VerticalMarqueeTextView 添加到我的项目中,然后在 onCreate() 等中引用它?
    • 是的,你是对的.. 不要忘记将你的 textview xml 设置为 &lt;com.package.project.VerticalMarqueeTextView ..... /&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    相关资源
    最近更新 更多