首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android -为文本视图创建类似于电影字幕的向上滑动动画

Android -为文本视图创建类似于电影字幕的向上滑动动画
EN

Stack Overflow用户
提问于 2020-05-14 18:34:55
回答 1查看 193关注 0票数 0

我使用的是w TextSwitcher,看起来像这样:

activity_main.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

代码语言:javascript
复制
<TextSwitcher
    android:id="@+id/simpleTextSwitcher"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:measureAllChildren="true">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textAlignment="center"
        android:textSize="20sp"
        tools:text="Opening Credits" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="main star: James bond"
        android:textAlignment="center"
        android:textSize="20sp" />

</TextSwitcher>

我想为文本切换器创建一个滑入和滑出动画,这样看起来就像电影片头的场景,下一个文本从底部滑入,而从顶部滑入的文本通过向上滑动消失。我已经尝试了一些事情,但都没有成功。这是我到目前为止所知道的:

我的slide_in.xml动画:

代码语言:javascript
复制
<translate
    android:duration="1000"
    android:fromYDelta="100%"
    android:toYDelta="0"
    />

和我的slide_out.xml动画:

代码语言:javascript
复制
<translate
    android:duration="1000"
    android:fromYDelta="100%"
    android:toYDelta="0%p"
    />

我对幻灯片动画有困难。

我想弄清楚我在这里想要什么。我希望当前在textSwitcher中可见的任何内容都向上滑动,并且不再被看到,然后立即有一个新的文本从底部滑动来取代它。

下面是我如何简单地调用它:

代码语言:javascript
复制
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    container.setOnClickListener { showNextText(it) }
    simpleTextSwitcher.setCurrentText("Opening Credits");

    val textAnimationIn =  AnimationUtils.
        loadAnimation(this,   R.anim.slide_in);

    val textAnimationOut =  AnimationUtils.
    loadAnimation(this,   R.anim.slide_out);

    simpleTextSwitcher.setInAnimation(textAnimationIn);
    simpleTextSwitcher.setOutAnimation(textAnimationOut);
}

 fun showNextText( view: View){
        simpleTextSwitcher.setText("main star: james bond");
}

}

下面是它现在的表现:

我想要发生的是,“开场字幕”一直滑到屏幕的顶部,而且永远不会出现。然后让文本“主要明星:詹姆斯·邦德”从底部滑到它的位置。你能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-14 22:00:46

我想出来了,...here就是幻灯片:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"  >

    <translate
        android:duration="1000"
    android:fromYDelta="100%p"
    android:toYDelta="0%" />

</set>

然后是幻灯片:

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" android:fillAfter="true" >

    <translate
        android:duration="1000"
        android:fromYDelta="0%"
        android:toYDelta="-100%p" />

</set>

this page对我非常有用,因此我可以知道p在fromYDelta中代表什么

以下是最终结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61795170

复制
相关文章

相似问题

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