当在屏幕上显示时,AnimationDrawable大于指定的值

时间:2018-06-26 17:23:07

标签: android

我有一个tap_animation.xml文件,该文件是:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/tap_1" android:duration="1000" android:layout_width="@dimen/width_of_overlay" android:layout_height="@dimen/height_of_overlay"/>
    <item android:drawable="@drawable/tap_2" android:duration="1500" android:layout_width="@dimen/width_of_overlay" android:layout_height="@dimen/height_of_overlay"/>

</animation-list>

dimens.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="width_of_overlay">32dp</dimen>
    <dimen name="height_of_overlay">32dp</dimen>
</resources>

当我将ImageView的背景设置为上述动画时,启动动画,并将ImageView添加到当前显示的布局中,即使我指定了图像,该图像也为全尺寸为32dp x 32dp。以下runnable可以执行我刚才提到的内容。

    tap_iv.setX(MainActivity.screen_width_px/2 - tap_animation.getFrame(0).getIntrinsicWidth()/2);
    tap_iv.setY(score_bar_height + get_game_surface().get_surface_height()/2 - tap_animation.getFrame(0).getIntrinsicHeight()/2);
    tap_r = new Runnable(){
        public void run(){
            tap_iv.setBackground(tap_animation);
            tap_animation.start();
            current_layout.addView(tap_iv);
        }
    };

有什么方法可以保持32x32dp大小?

0 个答案:

没有答案