这是xml的代码:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/minepic" />
Run Code Online (Sandbox Code Playgroud)
这里的minepic是一个gif动画图像,但在运行应用程序后它只显示一个静态图像.
有没有关于如何在Android应用程序中动画.gif图像的解决方案?
我正在使用AnimationDrawable进行下载进度吧我将动画放入getview,它运行正常.但是当我滚动列表时,动画已被停止.在AnimationDrawable中有任何方法来解决这个问题.喜欢Dialog中的setCancelable.
请帮帮我...谢谢
ImageView anim = (ImageView) rootview.findViewById(R.id.imageView2);
AnimationDrawable animation = (AnimationDrawable) anim.getDrawable();
animation.start();
Run Code Online (Sandbox Code Playgroud)
截图:
我正在关注Google提供的如何将DynamicDrawable与ImageView一起使用的示例.您可以在此处找到它:http://developer.android.com/guide/topics/graphics/drawable-animation.html
imageView.setBackgroundResource(R.drawable.animation);
AnimationDrawable animation = (AnimationDrawable)imageView.getBackground();
animation.start();
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
Run Code Online (Sandbox Code Playgroud)
Google似乎认为这应该可行,但是如果你不能将BitmapDrawable强制转换为AnimationDrawable,我不确定它应该如何工作?
我有一个复杂的Battle系统,它有1个父Activity,然后是几个子类,通过扩展Battle并将上下文传递给这些类来访问BattleActivity的静态变量.
这一切似乎都运行正常,但是我在从内存中释放所有的AnimationDrawables时遇到了问题.在整个战斗中总共可以使用24个DrawableAnimations.现在这是可以的,但是每次用户遇到一个新的怪物时,就会有4个以上的AnimationDrawables被添加到内存中,这将慢慢地使得我的应用程序崩溃,并且内存不足异常.
因此,我真的需要找到一种方法来释放我的战斗系统在我退出时占用的所有内存.目前,我正在测试Sony Z2,当用户参加战斗时,记忆从91mb增加到230mb.当战斗迫使我需要将这个内存使用量降低到91mb.我添加了一些非常基本的代码片段,让您了解应用程序当前的流程以及我尝试释放内存的方法.
public class Battle extends Activity
{
// I have several AnimationDrawables loaded into memory
// These are then assigned the relevent animation to a button swicthing between these animations throughout my battle
ImageButton btnChr1;
AnimationDrawable cAnimHit1;
}
//This is the use of one of those AnimationDrawables
public class Battle_Chr_Anim extends Battle
{
protected Context ctx;
private ImageButton btnChr1;
AnimationDrawable cAnimHit1;
public Battle_Chr_Anim(Context c, ImageButton _btnChr1, AnimationDrawable _cAnimHit1) {
this.ctx = c;
this.btnChr1 = _btnChr1;
this.cAnimHit1 = …
Run Code Online (Sandbox Code Playgroud) java android memory-leaks memory-management animationdrawable
如何使用AnimationDrawable暂停帧动画?
我怎么能放弃fromFegrees
,toDegrees
和android:color="#000000"
编程?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="@android:color/transparent" android:width="10dp"/>
<solid
android:color="#000000" />
</shape>
</rotate>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我在视图的背景中使用此xml.
我必须以编程方式创建三角形.所以需要以编程方式创建RotationDrawable.
当我完成我的活动时,我应该使用clearAnimation()
还是stop()
使用任何剩余的AnimationDrawable
物体?
我在我的应用程序的许多活动中使用animationdrawables.这是对他们进行初步化的代码:
public void prepareVideo (int resourceBall, String animation, int width, int height ){
imgBall = (ImageView)findViewById(resourceBall);
imgBall.setVisibility(ImageView.VISIBLE);
String resourceNameAnimation = animation;
int id_res = getResources().getIdentifier(resourceNameAnimation, "drawable", getPackageName());
imgBall.setBackgroundResource(id_res);
LayoutParams latoutFrame = imgBall.getLayoutParams();
latoutFrame.width = width;
latoutFrame.height = height;
imgBall.setLayoutParams(latoutFrame);
frame = (AnimationDrawable) imgBall.getBackground();
}
Run Code Online (Sandbox Code Playgroud)
然后我调用:imgBall.post(new StartAnimation());
调用runnable:
class StartAnimation implements Runnable {
public void run() {
frame.start();
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我使用了许多动画,它们使用相同的xml(逐帧).我必须在具有相同动画的许多活动中调用此方法.最后,我得到了一个错误的错误.我试图在屏幕之间释放内存:
for (int i = 0; i < frame.getNumberOfFrames(); ++i){
Drawable frame_rescue = frame.getFrame(i);
if (frame_rescue instanceof BitmapDrawable) {
((BitmapDrawable)frame_rescue).getBitmap().recycle();
} …
Run Code Online (Sandbox Code Playgroud) 如何删除帧动画的背景(或将其设置为透明)?
当我将xml布局文件中的背景颜色设置为透明时,运行它时它会变成黑色。
当我setBackgroundColor(0); 在Java 代码中,我收到以下异常:
java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
/res/layout/dialog_loading.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background_black_semitransparent" >
<!-- The background of this LinearLayout is so that there is
a semi transparent black overlay over the application content
while the loading animation plays -->
<FrameLayout
android:layout_width="@dimen/dialog_width"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent" >
<ImageView
android:id="@+id/iv_loading"
android:layout_width="@dimen/dialog_width"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:background="@android:color/transparent" />
</FrameLayout>
</LinearLayout> …
Run Code Online (Sandbox Code Playgroud) android timer background-color android-animation animationdrawable
我想通过更改ImageView中的帧来创建一个简单的动画.我不想使用AnimationDrawable,因为我需要在帧更改或动画停止时接收事件,以便能够向后播放,重新启动它等等.
我的问题是虽然setImageDrawable被调用(在主线程上),但帧实际上并没有改变事件.所以每一件事似乎工作得很好,除了框架不会改变(实际上只绘制一个框架,第一个框架).
所以我的代码:
public class AnimatedImageView extends ImageView implements Animatable, Runnable {
private static final String TAG = "AnimatedImageView";
public static interface AnimationEventsListener {
void animationDidChangeFrame(AnimatedImageView animatedImageView);
void animationDidStop(AnimatedImageView animatedImageView);
}
/* frames - ress ids */
private int[] mFrameResIds;
/* current frame index */
private int mCurrentFrameIdx;
/* number of the current repeat */
private int loopIndex;
/* number of animation repetiotions, 0 for infinite */
private int mNumOfRepetitions;
/* if animation is playing */
private boolean playing;
/* …
Run Code Online (Sandbox Code Playgroud) animation android android-imageview animationdrawable android-drawable
第4个小时的搜索,没有结果都一样.我们不应该这样做的事实.告诉我如何实现以下内容:
有片动画xml:
Run Code Online (Sandbox Code Playgroud)<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <item android:drawable="@drawable/a1" android:duration="250"/> <item android:drawable="@drawable/a2" android:duration="250"/> <item android:drawable="@drawable/a3" android:duration="250"/> <item android:drawable="@drawable/a4" android:duration="250"/> <item android:drawable="@drawable/a5" android:duration="250"/> <item android:drawable="@drawable/a6" android:duration="250"/> <item android:drawable="@drawable/a7" android:duration="250"/> <item android:drawable="@drawable/a8" android:duration="250"/> <item android:drawable="@drawable/a9" android:duration="250"/> <item android:drawable="@drawable/a10" android:duration="250"/> <item android:drawable="@drawable/a11" android:duration="250"/> <item android:drawable="@drawable/a12" android:duration="250"/> <item android:drawable="@drawable/a13" android:duration="250"/> <item android:drawable="@drawable/a14" android:duration="250"/> <item android:drawable="@drawable/a15" android:duration="250"/> <item android:drawable="@drawable/a16" android:duration="250"/> <item android:drawable="@drawable/a17" android:duration="250"/> <item android:drawable="@drawable/a18" android:duration="250"/> <item android:drawable="@drawable/a19" android:duration="250"/> <item android:drawable="@drawable/a20" android:duration="250"/> <item android:drawable="@drawable/a21" android:duration="250"/> <item android:drawable="@drawable/a22" android:duration="250"/> <item android:drawable="@drawable/a23" android:duration="250"/> <item android:drawable="@drawable/a24" …
customization android asynctaskloader progress-bar animationdrawable
我正在尝试使用以下代码为示例程序设置动画:
AnimationDrawable animation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
ImageView animatedImage = (ImageView) findViewById(R.id.animation);
animatedImage.setBackgroundResource(R.drawable.animate_bag);
animation = (AnimationDrawable) animatedImage.getBackground();
}
public void startAnimate(View v)
{
if (animation != null)
animation.start();
} //eof OnClick
Run Code Online (Sandbox Code Playgroud)
XML 文件是:
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate"
android:onClick="startAnimate" />
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/animate_bag" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是 animationImage.getBackground() 返回 null。
会欣赏你的提示:-)
谢谢,西蒙