/* drawable 转换成bitmap */
private Bitmap drawableToBitmap(Drawable drawable)
{
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
// 取drawable的颜色格式
Bitmap.Config config =
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// 建立对应bitmap
Bitmap bitmap = Bitmap.createBitmap(width, height, config);
// 建立对应bitmap的画布
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
// 把drawable内容画到画布中
drawable.draw(canvas);
return bitmap;
}
}
3、定义动画文件
accelerate_interpolator.xml
<?xml version="1.0" encoding="utf-8"?>
<accelerateInterpolator />
decelerate_interpolator.xml
<?xml version="1.0" encoding="utf-8"?>
<decelerateInterpolator />
status_view_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@anim/decelerate_interpolator">
<translate android:fromYDelta="75%" android:toYDelta="0"
android:duration="1000"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="1000" />
</set>
status_view_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@anim/accelerate_interpolator">
<translate android:fromYDelta="0" android:toYDelta="75%"
android:startOffset="100" android:duration="1000"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:startOffset="100" android:duration="1000" />
</set>
说明:zoomDrawable()方法和drawableToBitmap()来源网络。