Android的动画离开运动期间线路 [英] Android Animation leaves lines during movement

查看:130
本文介绍了Android的动画离开运动期间线路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AbsoluteLayout一个3x4的网格12 ImageButtons设置。当用户点击图像按钮它长到填满整个屏幕,持有,然后逐渐缩小到原来的位置。

I have 12 ImageButtons setup in a 3x4 grid using an AbsoluteLayout. When the user clicks on an image button it grows to fill the screen, holds, and then shrinks down to its original location.

的动画作品除了当按钮被缩小有时离开后方。 (我在下面附加的图片)。

The animation works except that when the button is shrinking it sometimes leaves lines behind. (I've attached images below).

有没有更好的方式来实现这个动画?我能做些什么,以prevent说我得到了绘图错误?

Is there a better way to achieve this animation? What can I do to prevent the drawing errors that I'm getting?

修改
还行,一旦消失收缩动画完成,他们只在动画过程present。

EDIT: Also the lines disappear as soon as the shrink animation finishes, they are only present during the animation.

下面是我的 UDATED 动漫code

Here is my UDATED animation code

private void animateCard(final CardButton c){
    this.isAnimating = true;
    CardPickerActivity.this.soundManager.playSound(c.name);
    Util.logD("Card:" + c.name + " clicked!");

    final int growDuration = 750;
    final int holdDuration = 500;
    final int shrinkDuration = 500;

    c.bringToFront();
    AnimationSet asGrow = new AnimationSet(true);
    float newScale = 2.0f;
    float newX = (CardPickerActivity.this.wDesk/2.0f - CardPickerActivity.this.cardSize/2.0f*newScale - c.getLeft())/newScale;
    float newY = (CardPickerActivity.this.hDesk/2.0f - CardPickerActivity.this.cardSize/2.0f*newScale - c.getTop() )/newScale;
    TranslateAnimation taG = new TranslateAnimation(0.0f, newX , 0.0f, newY);
    ScaleAnimation saG = new ScaleAnimation(    1.0f, newScale, 1.0f, newScale);

    taG.setRepeatCount(1);
    saG.setRepeatCount(1);
    taG.setRepeatMode(Animation.REVERSE);
    saG.setRepeatMode(Animation.REVERSE);

    asGrow.addAnimation(taG);
    asGrow.addAnimation(saG);
    asGrow.setDuration(growDuration);


    c.startAnimation(asGrow);

}

下面是该活动的XML布局,忽略layout_x和layout_y我后来他们设置基于设备的屏幕:

Here is the XML Layout for the activity, ignore the layout_x and layout_y I set them later based upon the screen of the device:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cardLayout" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.myProject.CardButton
        android:id="@+id/btn1" android:text="1" android:layout_x="0px"
        android:layout_y="0px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn2" android:text="2" android:layout_x="10px"
        android:layout_y="10px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn3" android:text="3" android:layout_x="20px"
        android:layout_y="20px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn4" android:text="4" android:layout_x="30px"
        android:layout_y="30px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn5" android:text="5" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn6" android:text="6" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn7" android:text="7" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn8" android:text="8" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn9" android:text="9" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn10" android:text="10" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn11" android:text="11" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <com.myProject.CardButton
        android:id="@+id/btn12" android:text="12" android:layout_x="40px"
        android:layout_y="40px" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</AbsoluteLayout>

下面是CardButton类,它实质上是一个带有几个成员变量的ImageButton的

Here is the CardButton class, its essentially an ImageButton with a few more member variables

public class CardButton extends ImageButton {
    public CardButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    public CardButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CardButton(Context context) {
        super(context);
    }

    public String name;
    public Bitmap image;

    public int soundRes;
    public int imageRes;

    public String customImagePath;
    public String customSoundPath;
}

推荐答案

所以,我解决了这个问题,但不是在说我很高兴的一种方式。

So I solved the problem but not in a way that I'm happy with.

首先在我的code的地方,我不显示我叫:

First at a place in my code I wasn't showing I called:

cardButton.setBackgroundColor(Color.WHITE);

如果我评论了这条线的问题就走了。然而,这产生的,看起来像普通的Andr​​oid按键CardButtons。这不是我希望他们看,所以我尝试设置白色按钮风格的一些其他方式。所有这一切产生的错误。

If I commented out this line the problem went away. This however produced CardButtons that looked like stock android buttons. This isn't how I wanted them to look, so I tried setting the white button "style" a number of other ways. All of which produced the bug.

在试图更好地了解发生了什么事情,并在Android或我的code我创建了一个测试项目,只有包含在3x4的网格,没有别的一个活动追捕一个可能的错误。这个测试项目包含一个活动和一个XML文件。一个基本的网格我是联合国能够重现错误开始,然后我就开始增加越来越多的功能来测试应用程序,并最终不得不重新创建原来的活动,但没有错误。

In an attempt to better understand what was going on and to hunt down a possible bug in either Android or my code I created a test project that only included one activity with the 3x4 grid and nothing else. This test project contained a single activity and a single XML file. Starting with a basic grid I was un able to reproduce the bug, then I started adding more and more features to the test app and eventually had recreated the original activity but without the bug.

我想,也许一些关于我的新的实现比原来的更好,所以我成立了新的测试活动到我原来的项目。然而,当我跑从原来的项目测试活动的错误再次出现了。

I thought maybe something about my new implementation was better than the original so I incorporated the new test activity into my original project. However, when I ran the test activity from original project the bug showed up again.

我现在有使用在不同的Andr​​oid项目相同code两项活动。一是在项目唯一的活动,而另一种是有许多活动一个更大的项目的一部分。在大项目的版本显示的bug,而在单机项目版本不。我不知道如何跨preT这一点,我会非常AP preciate任何反馈/关于这个问题的。

I now have two activities that use identical code in different Android Projects. One is the only activity in the project while the other is part of a larger project with many activities. The version in the larger project exhibits the bug while the version in the stand alone project does not. I'm not sure how to interpret this and I'd greatly appreciate any feedback/comments on this.

所以,直到我能弄清楚,为什么我得到的图纸错误在我更大的应用程序,我将使用普通的Andr​​oid按钮背景的环境。

So until I can figure out why I get the drawing error in the context of my bigger application I'm going to use the stock android button background.

更新:在一个心血来潮我做了一个9Patch背景是白色的。这解决了问题。

Update: On a whim I made a 9Patch background that was white. This fixed the problem.

这篇关于Android的动画离开运动期间线路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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