android - 具有 scale 属性的 ObjectAnimator 使 bg 变黑?

标签 android android-animation android-view

我使用 ObjectAnimator 缩小 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();

它按预期缩小得很好,但问题是现在较小的 View 周围的区域是黑色的,直到另一个用户操作,这是不希望的。我希望它与缩放 View 的父级背景相匹配。知道如何立即使红色方 block 周围的区域具有正确的颜色吗?

enter image description here

我的 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>

最佳答案

之前的答案之所以需要让parent失效是因为你的AnimatorSet scaleDown没有Target。您应该将 ObjectAnimator 的 Target 设置为 null,并在 AnimatorSet 上设置 Target。或者更好的方法是使用下面的代码:

ObjectAnimator scaleDown = ObjectAnimator.ofPropertyValuesHolder(view, 
    PropertyValuesHolder.ofFloat("scaleX", 0.5f),
    PropertyValuesHolder.ofFloat("scaleY", 0.5f));
scaleDown.setDuration(1000);
scaleDown.start();

关于android - 具有 scale 属性的 ObjectAnimator 使 bg 变黑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926117/

相关文章:

android - 如何在 android 上将 WHERE 子句添加到查询

jQuery 和 UI 设计中的 android phonegap 应用程序问题

java - 执行 View 切换时无法在ViewAnimator中实现动画效果

android - 如何在android中的imageview中添加gif图像?

android - 将 View 移出约束布局

java - 从RadioButton传递字符串android :text ="@string/blue" to the next activity in android

android - 在Android应用程序中显示大量数据(大多数文本)

android - 如何从不同角度旋转 View ?

android:contentInsetLeft ="0dp"与 app:contentInsetLeft ="0dp"

Android Activity 未在 onTouch 功能中启动