Android 影响缩放类型或将矩阵应用于AnimationDrawable
我很容易让AnimationDrawable正常工作,但它总是延伸到ImageView的全部大小(如果我有布局高度、宽度来填充父视图)。有趣的是,当我将布局高度、宽度设置为任何其他值(包裹内容、特定像素等)时,动画根本不会显示。不管我使用的是Image setImage还是setBackgroundImage,结果都是一样的 理想的情况是,我可以将现有矩阵应用于整个animationdrawable列表 这是代码。。。 `Android 影响缩放类型或将矩阵应用于AnimationDrawable,android,animation,matrix,bitmap,drawable,Android,Animation,Matrix,Bitmap,Drawable,我很容易让AnimationDrawable正常工作,但它总是延伸到ImageView的全部大小(如果我有布局高度、宽度来填充父视图)。有趣的是,当我将布局高度、宽度设置为任何其他值(包裹内容、特定像素等)时,动画根本不会显示。不管我使用的是Image setImage还是setBackgroundImage,结果都是一样的 理想的情况是,我可以将现有矩阵应用于整个animationdrawable列表 这是代码。。。 ` wxChartAnimation=newanimationdrawabl
wxChartAnimation=newanimationdrawable();
int numCharts=subChart.getChartCount();
对于(int i=0;i
我也有这个问题。为了它的价值,我遇到了一个针对我的目的的黑客解决方法。似乎当您使用“new AnimationDrawable()”以编程方式创建AnimationDrawable时,它将不考虑ImageView的scaleType。但是,如果使用.anim xml资源并在该引用资源可绘制文件中包含帧列表,则它将采用第一幅图像的大小,并根据ImageView的缩放类型适当缩放动画。由于我试图将图像从assets文件夹加载到AnimationDrawable中,所以我需要从代码中执行此操作。我最后做了以下几件事:
在res/anim/empty.xml中(其中empty_slide是一个透明图像,大小与我将在动画的其余部分中使用的大小相同):
我很想知道你是否找到了更好的方法…我正在寻找另一种方法 问题是-“new AnimationDrawable()”不设置CurrentDrawable=>不设置AnimationDrawable的高度和宽度 我这样解决了这个问题:
protected void playFrameAnimationWithCurrentFrame(final ImageView ImView,final AnimationDrawable AnimDrawable){
ImView.post(new Runnable(){
public void run(){
AnimDrawable.start();
}});//We start the animation so that we have the current frame on which the matrix for mapping is based
Thread t = new Thread() {
@Override
public void run() {
while(AnimDrawable.getCurrent()==null){//wait for the current frame to appear
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ImView.post(new Runnable(){//stop the current animation to assign animation to view and restart
public void run(){
AnimDrawable.stop();
}});
runOnUiThread(new Runnable() {
@Override
public void run() {
ImView.setImageDrawable(AnimDrawable);}
});
ImView.post(new Runnable(){
public void run(){
AnimDrawable.start();}});
interrupt();
}};
t.start();
}
之后,动画将与我们之前安装在ImageView上的矩阵一起播放
此方法不需要.xml资源文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/empty_slide" android:duration="0" />
</animation-list>
imageView.setImageResource(R.anim.empty);
AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getDrawable();
animationDrawable.addFrame(Drawable.createFromStream(context.getAssets().open(drawablePath), null),animationDuration);
// Add the rest of the frames
...
animationDrawable.start();
protected void playFrameAnimationWithCurrentFrame(final ImageView ImView,final AnimationDrawable AnimDrawable){
ImView.post(new Runnable(){
public void run(){
AnimDrawable.start();
}});//We start the animation so that we have the current frame on which the matrix for mapping is based
Thread t = new Thread() {
@Override
public void run() {
while(AnimDrawable.getCurrent()==null){//wait for the current frame to appear
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ImView.post(new Runnable(){//stop the current animation to assign animation to view and restart
public void run(){
AnimDrawable.stop();
}});
runOnUiThread(new Runnable() {
@Override
public void run() {
ImView.setImageDrawable(AnimDrawable);}
});
ImView.post(new Runnable(){
public void run(){
AnimDrawable.start();}});
interrupt();
}};
t.start();
}