I have a list view, which contains an icon, a title and a subtitle.
My boss asks me that he wants to change that icon into something animation. When he mean animation, it is just display three images continues, makes it look like animation.
I already make the animation work, by writing a xml in res/anim folder:
<?xml version="1.0" encoding="UTF-8"?>
<animation-list android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="150" android:drawable="@drawable/icon_anmi_1"/>
<item android:duration="150" android:drawable="@drawable/icon_anmi_2" />
<item android:duration="150" android:drawable="@drawable/icon_anmi_3" />
</animation-list>
And by writing another progress bar style in value folder:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="animStyle" parent="@android:style/Widget.ProgressBar.Small">
<item name="android:indeterminateDrawable">@anim/icon_anim</item>
</style>
</resources>
I using progress bar since the icon should start animation automatic. Which it does. Also, in my list adapter's xml layout:
<?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="60dip"
android:padding="10dip"
>
<ProgressBar android:id="@+id/itemIcon" style="@style/animStyle"
android:layout_width="60px"
android:layout_height="60px"
android:layout_marginRight="10dip"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/itemInfo"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/itemIcon"
android:gravity="center_vertical"
android:textSize="18sp"
android:textStyle="bold"
android:ellipsize="marquee" android:singleLine="true"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/itemIcon"
android:gravity="center_vertical"
android:textSize="10sp"
android:ellipsize="marquee" android:singleLine="true" android:layout_below="@+id/itemInfo"/>
</RelativeLayout>
I also make changes in my code when binding adapter to list item:
adapterForList= new SimpleAdapter(this, hashMapListForListView, R.layout.s_item, new String[]{"imageUri","title","subtitle"},new int[]{R.id.itemIcon,R.id.itemInfo,R.id.subtitle});
adapterForList.setViewBinder(new SimpleAdapter.ViewBinder() {
public boolean setViewValue(View view, Object data,
String textRepresentation) {
if (view.getId() == R.id.itemIcon) {
//Not need progress
//int value = Integer.parseInt(data.toString());
//((ProgressBar) view).setProgress(value);
return true;
}
return false;
}
});
lv.setAdapter(adapterForList);
The animation works fine. The only problem I face now is that the image I put for animation can't be resized to the correct size. It can only display part of it. I wonder if there is a way to let me define the size of the image to display so it could be work as fine as a image view.
Thank you!