具有scale属性的ObjectAnimator使bg黑色? [英] ObjectAnimator with scale property makes bg black?

查看:90
本文介绍了具有scale属性的ObjectAnimator使bg黑色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ObjectAnimator缩小RelativeLayout的比例:

I use ObjectAnimator to scale down a RelativeLayout :

            ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 0.5f);
            ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 0.5f);
            scaleDownY.setDuration(1000);
            AnimatorSet scaleDown = new AnimatorSet();
            scaleDown.play(scaleDownX).with(scaleDownY);
            scaleDown.start();

它按比例缩小得很好,但是问题是,现在较小的视图周围的区域变为黑色,直到出现另一个用户操作为止,这是不希望的.我希望它与缩放视图的父级的背景匹配.您知道如何立即使红色方块周围的区域具有正确的颜色吗?

It scales down pretty well as expected, but the problem is that the area around now smaller view is black until another user action, which is undesirable. I want it to match the background of the scaled view's parent. Any idea how to make the area around red square have the correct color immediately ?

我的xml:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:gui="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/bg"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$DummySectionFragment">
      <RelativeLayout
        android:id="@+id/res1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:tag="res1"
        android:background="@android:color/holo_red_dark"
        android:layout_alignTop="@+id/res2"
        android:layout_alignRight="@+id/include3"
        android:layout_marginRight="11dp">
            <TextView
                android:layout_marginLeft="15dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="res1"
                android:id="@+id/res1T"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"/>
        </RelativeLayout>
    </RelativeLayout>

推荐答案

这可能不是最干净的解决方案,但是添加动画更新侦听器并使父级无效可能会胜任.

It may not be the cleanest solution, but adding animation update listener and invalidating the parent might do the job.

ObjectAnimator scaleDownX = ObjectAnimator.ofFloat(view, "scaleX", 0.5f);
ObjectAnimator scaleDownY = ObjectAnimator.ofFloat(view, "scaleY", 0.5f);
scaleDownX.setDuration(1000);
scaleDownY.setDuration(1000);

AnimatorSet scaleDown = new AnimatorSet();
scaleDown.play(scaleDownX).with(scaleDownY);

scaleDownX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
     @Override
     public void onAnimationUpdate(ValueAnimator valueAnimator) {
         View p= (View) v.getParent();
         p.invalidate();
     });
scaleDown.start();

这篇关于具有scale属性的ObjectAnimator使bg黑色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆