标签: viewpropertyanimator

Android属性动画:如何增加视图高度?

如何使用Android中的属性动画增加视图高度?

ObjectAnimator a = ObjectAnimator.ofFloat(viewToIncreaseHeight, "translationY", -100);
a.setInterpolator(new AccelerateDecelerateInterpolator());
a.setDuration(1000);
a.start();
Run Code Online (Sandbox Code Playgroud)

translationY实际上移动视图而不是增加高度.如何增加视图的高度?

java android android-animation objectanimator viewpropertyanimator

50
推荐指数
4
解决办法
4万
查看次数

android animate()withEndAction()vs setListener()onAnimationEnd()

我经常使用ViewPropertyAnimator并使用withEndAction()函数设置结束动作,如:

view.animate().translationY(0).withEndAction(new Runnable() {
    @Override
    public void run() {
        // do something
    }
}).start();
Run Code Online (Sandbox Code Playgroud)

但您也可以设置结束动作设置特殊监听器,如:

view.animate().translationY(0).setListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        // do something
    }
});
Run Code Online (Sandbox Code Playgroud)

那么这两种方法之间有什么区别,何时应该使用它们?

android android-animation viewpropertyanimator

21
推荐指数
1
解决办法
3830
查看次数

如何在使用动画制作器激活其某些属性后将视图重置为原始状态?

我正在使用动画师(ObjectAnimator)为视图的一些属性(缩放,旋转)设置动画.

当ObjectAnimators设置为目标视图时,目标视图可以正常设置动画.

但是还需要在一段时间后查看原始位置 (重置).

我试图取消()动画师,但它只取消动画并且不重置视图.

可能的解决方案:创建另一个与初始动画师完全相反的动画师.

有没有其他方法可以重置它?

animation android objectanimator viewpropertyanimator

20
推荐指数
1
解决办法
5475
查看次数

Android - 使用AnimatorSet缩放动画

官方缩放视图教程使用a AnimatorSet来放大View.随着视野的扩大,它会产生向下运动的错觉.之后,AnimatorSet只是向后重放以创建缩小的幻觉.

放大向下移动 我需要实现的是与此完全相反的.我需要从扩展视图开始,然后将其缩小为一个向上移动的较小视图:

向上移动缩小 我似乎不能在示例中使用反转代码.该示例假定您首先放大视图并展开它,然后将其缩小回原始缩略图图标.

这是我到目前为止所尝试的内容.我的XML布局是

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#1999da">             

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:gravity="center">

        <!-- The final shrunk image -->

        <ImageView
            android:id="@+id/thumb_button_1"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_marginRight="1dp"
            android:visibility="invisible"/>

    </LinearLayout>

</LinearLayout>

<!-- The initial expanded image that needs to be shrunk -->

<ImageView
    android:id="@+id/expanded_image"
    android:layout_width="wrap_content"
    android:layout_height="125dp"
    android:layout_gravity="center"
    android:src="@drawable/title_logo_expanded"
    android:scaleType="centerCrop"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是执行缩小操作的方法.我基本上试图颠倒教程中的过程:

private void zoomImageFromThumbReverse(final View expandedImageView, int imageResId, final int duration) {
    // If there's an animation in …
Run Code Online (Sandbox Code Playgroud)

java android android-animation objectanimator viewpropertyanimator

15
推荐指数
1
解决办法
2926
查看次数

获取父布局的宽度

Android Studio 2.0 beta 6
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用ViewPropertyAnimator移动ImageView (ivSettings)工具栏内部,使其从右侧20dp,从顶部20dp,从当前位置.并ImageView (ivSearch)从左侧和顶部移动20dp.

imageViews包含在Toolbar.

这是初始状态,我想将图标移动到工具栏内的上角.

在此输入图像描述

我正在使用的代码是获取宽度然后减去一个值以使ivSettings从右边获得20dp.

final DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
final float widthPx = displayMetrics.widthPixels;

ivSearch.animate()
    .setInterpolator(new AccelerateInterpolator())
    .x(20)
    .y(20)
    .setDuration(250)
    .start();

ivSettings.animate()
    .setInterpolator(new AccelerateInterpolator())
    .x(widthPx - 160)
    .y(20)
    .setDuration(250)
    .start();
Run Code Online (Sandbox Code Playgroud)

但是,在不同的屏幕尺寸上试过这个,我无法得到精确的宽度计算.有没有更好的方法呢?

非常感谢任何建议

animation android viewpropertyanimator

12
推荐指数
2
解决办法
671
查看次数

如何重复属性动画?

我正在屏幕上做一个气泡动画,但是在完成动画时间后气泡停止了.如何重复动画或使其无限?

bub.animate();
bub.animate().x(x2).y(y2);
bub.animate().setDuration(animationTime);       
bub.animate().setListener(new AnimatorListenerAdapter() {

    @Override
    public void onAnimationStart(Animator animation) {
        animators.add(animation); 
    } 

    @Override
    public void onAnimationRepeat(Animator animation) {
    }

    @Override
    public void onAnimationEnd(Animator animation) {
    }
});
Run Code Online (Sandbox Code Playgroud)

animation android android-animation viewpropertyanimator

7
推荐指数
4
解决办法
6945
查看次数

无法删除ViewPropertyAnimator的侦听器

当我跑我的自定义视图里面的代码,onAnimationStartonAnimationEnd保持被重复调用.这不是很奇怪吗?作为Android程序员,我预计它们只会被分别调用一次.

    final ViewPropertyAnimator animator = animate().setDuration(1000).alpha(0.0f);
    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            Utils.log("----------------start");
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            Utils.log("--------- end");
        }
    }).start();
Run Code Online (Sandbox Code Playgroud)

但后来我尝试通过在onAnimationEndViewPropertyAnimators 调用时删除监听器来解决问题,setListener(null)但是尽管在文档中写了什么,它仍然无法工作:

public ViewPropertyAnimator setListener (Animator.AnimatorListener listener)

Added in API level 12
Sets a listener for events in the underlying Animators that run the property animations.

Parameters
listener    The listener to be called with AnimatorListener events. A value of null removes any existing …
Run Code Online (Sandbox Code Playgroud)

android viewpropertyanimator

7
推荐指数
1
解决办法
3032
查看次数

像在Gmail应用中切换帐户的动画

Gmail应用导航视图

将点击的图像翻译为活动帐户图像,并将活动帐户图像从其位置淡入淡出到点击图像的位置.

android viewanimator material-design viewpropertyanimator

7
推荐指数
1
解决办法
1373
查看次数

Android ObjectAnimator与ViewPropertyAnimator

ObjectAnimator和ViewPropertyAnimator改变属性值有什么区别?

ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(myObject, "X", 0.0f, 100.0f);
Run Code Online (Sandbox Code Playgroud)

我正在尝试myObject.getX()上面objectAnimator正在进行中,并且我在0.0f到100.0之间获得了一个在路上的值.

myObject.setX(0.0f);
myObject.animate().x(100.0f);
Run Code Online (Sandbox Code Playgroud)

但是,我得到了精确的100.0当我myObject.getX()倒是而上述ViewPropertyAnimator工作正在进行中.

我无法弄清楚是什么造成了这种差异.

提前致谢.

java android objectanimator animator viewpropertyanimator

6
推荐指数
1
解决办法
2343
查看次数

'错误:环境顶点缓冲区溢出!!!已使用304,共260'Android ViewPropertyAnimator

我在android中使用如下所述的视图属性动画器。它在大多数设备上都能正常工作,但在某些设备上会出现上述错误。它也总是在模拟器中失败。对象动画师也有同样的问题。请注意,动画仅在应用于单个视图时才有效,但不适用于具有多个子视图的容器。请帮助

    wordViewPropertyAnimator.rotationYBy(-90f).setDuration(resources.getInteger(R.integer.rotateAnimationHalf))
            .setListener(new AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    wordViewPropertyAnimator.setListener(null);
                    wordViewPropertyAnimator.rotationYBy(-180f).setDuration(0).start();

                    wordViewPropertyAnimator.rotationYBy(-90f).
                            setDuration(resources.getInteger(R.integer.rotateAnimationHalf)).start();                       

                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            })
            .start();
Run Code Online (Sandbox Code Playgroud)

ObjectAnimator objectAnimator=ObjectAnimator.ofFloat(wordView, View.ROTATION_Y, -90f); objectAnimator.setDuration(200); objectAnimator.start();

android viewpropertyanimator

1
推荐指数
1
解决办法
675
查看次数