Android 从服务器获取用于动画的资源
我已经开发了一个应用程序,它具有逐帧动画。我正在从drawable文件夹获取资源。因此,我的apk的大小是巨大的。现在我想从服务器上获取资源,但我想不出一个方法来实现这一点。 我把代码放在这里了 main.xml::Android 从服务器获取用于动画的资源,android,Android,我已经开发了一个应用程序,它具有逐帧动画。我正在从drawable文件夹获取资源。因此,我的apk的大小是巨大的。现在我想从服务器上获取资源,但我想不出一个方法来实现这一点。 我把代码放在这里了 main.xml:: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation=
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/simple_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, XMLAnimation"
/>
<Button android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
<animation-list xmlns:android=
"http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/girl0001" android:duration="20" />
<item android:drawable="@drawable/girl0002" android:duration="20" />
<item android:drawable="@drawable/girl0003" android:duration="20" />
<item android:drawable="@drawable/girl0004" android:duration="20" />
<item android:drawable="@drawable/girl0005" android:duration="20" />
<item android:drawable="@drawable/girl0006" android:duration="20" />
</animation-list>
我认为这真的取决于你想做什么,以及你的动画是什么。一些更简单的动画(例如旋转)可以不制作单个可绘制的动画,从而可以存储更少的资源。如果您处理的是非常复杂的动画和潜在的许多资产,那么您可以始终从服务器返回数据,这些数据可以由客户端逻辑以编程方式(而不是通过xml)解释为动画 在此线程中还讨论了在运行时使用XML文件:
我认为这实际上取决于你想做什么,以及你的动画是什么。一些更简单的动画(例如旋转)可以不制作单个可绘制的动画,从而可以存储更少的资源。如果您处理的是非常复杂的动画和潜在的许多资产,那么您可以始终从服务器返回数据,这些数据可以由客户端逻辑以编程方式(而不是通过xml)解释为动画 在此线程中还讨论了在运行时使用XML文件:
我已通过以下方式解决此问题:
ImageView img = (ImageView) findViewById(R.id.simple_anim);
animation = new AnimationDrawable();
try {
for(int i=0;i<54;i++)
{
xyz("girl000",i);
}
animation.setOneShot(false);
} catch (Exception e) {
}
img.setBackgroundDrawable(animation);
img.post(new Starter());
}
public void xyz(String str,int x)
{
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
"http://sdfsdffff/MRESC/images/test/girl/"+"girl000"+x+".png")
.getContent());
Drawable frame =new BitmapDrawable(bitmap);
animation.addFrame(frame, 50);
} catch (Exception e) {
}
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
ImageView img=(ImageView)findviewbyd(R.id.simple\u anim);
animation=新的AnimationDrawable();
试一试{
对于(int i=0;i,我通过以下方法求解:
ImageView img = (ImageView) findViewById(R.id.simple_anim);
animation = new AnimationDrawable();
try {
for(int i=0;i<54;i++)
{
xyz("girl000",i);
}
animation.setOneShot(false);
} catch (Exception e) {
}
img.setBackgroundDrawable(animation);
img.post(new Starter());
}
public void xyz(String str,int x)
{
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
"http://sdfsdffff/MRESC/images/test/girl/"+"girl000"+x+".png")
.getContent());
Drawable frame =new BitmapDrawable(bitmap);
animation.addFrame(frame, 50);
} catch (Exception e) {
}
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
ImageView img=(ImageView)findviewbyd(R.id.simple\u anim);
animation=新的AnimationDrawable();
试一试{
对于(int i=0;i