我有一个4帧的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/male01a" android:duration="4000" />
<item android:drawable="@drawable/male01b" android:duration="1100" />
<item android:drawable="@drawable/male01c" android:duration="1100" />
<item android:drawable="@drawable/male01d" android:duration="300" />
</animation-list>
无论如何我可以在这里为每个drawable使用某种变量吗?就像使用&#34; @ string / animation1&#34;其中animation1指向&#34; @ drawable / male01a&#34;在Strings.xml中。但我需要一些方法来改变drawables,比如说代码中的male02a。
答案 0 :(得分:0)
我不确定你的目标是什么:
您可以以编程方式将特定项目的drawable(image)更改为listView。 您需要制作自己的xml文件来描述这些项目。
示例“list_item.xml”:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="@string/image"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:paddingBottom="10dp"
android:textColor="#CC0033"
android:textSize="16dp" />
<TextView
android:id="@+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/icon"
android:paddingLeft="10dp"
android:textColor="#3399FF"
android:textSize="14dp" />
</RelativeLayout>
如果你想为整个listView制作一个动画,我建议你试试这个库: ListViewAnimations
答案 1 :(得分:0)
您可以使用方法addFrame()将帧动态添加到动画中。
示例:
ImageView imview = (ImageView) findViewById(R.id.ivImage);
AnimationDrawable ad = (AnimationDrawable) imview.getDrawable();
Drawable frame = Drawable.createFromPath("your image path");
ad.addFrame(ad, 200);