根据textview对textview进行动画处理

问题描述 投票:-1回答:1

我有一个垂直线性布局,其中有两个textview,我在第一个textview中添加了textsize动画因此,问题在于当文本视图较大时,每当在上部textview中添加新行时,下部textview就会向下移动而没有动画。它只是从以前的位置弹出,然后在新位置弹出。当第一个textview的高度发生变化时,如何为第二个textview设置动画?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/one"
        android:text="one two three four five"
        android:textSize="@dimen/TEXT_SIZE_18"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/two"
        android:text="six seven eight nine ten"
        android:textSize="@dimen/TEXT_SIZE_18"/>

</LinearLayout>

我为一个文本视图的尺寸设置了动画

final float startSize = 18; // Size in pixels
final float endSize = 24;
long animationDuration = 600; // Animation duration in ms

ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize);
animator.setDuration(animationDuration);

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float animatedValue = (float) valueAnimator.getAnimatedValue();
        if (one!=null){
            one.setTextSize(animatedValue);
        }
    }
});

我希望两个textview自动动画

我有一个垂直的线性布局,其中有两个textview,我在第一个textview中添加了textsize动画,所以问题是当文本视图更大时,每当在上方添加新行时...

android animation transition
1个回答
0
投票

一种简单的方法就是使用LayoutTransition。可以使用ViewGroup属性在android:animateLayoutChanges="true"上启用wihich。

© www.soinside.com 2019 - 2024. All rights reserved.