ProgressBar使用动画6.0 及6.0以下的坑
最近用ProgressBar 做了几个gif,但是同一套代码6.0是好的,6.0以下会出现图片无法适应ProgressBar 且被拉伸的情况。解决方案如下:
6.0的动画定义
<?xml version="1.0" encoding="UTF-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@mipmap/animation_no_available_1"
android:duration="500"/>
<item
android:drawable="@mipmap/animation_no_available_2"
android:duration="500"/>
</animation-list>
6.0以下的动画定义
<?xml version="1.0" encoding="UTF-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="500">
<clip
android:clipOrientation="horizontal"
android:drawable="@mipmap/animation_no_available_1"
android:gravity="center" >
</clip>
</item>
<item android:duration="500">
<clip
android:clipOrientation="horizontal"
android:drawable="@mipmap/animation_no_available_2"
android:gravity="center" >
</clip>
</item>
</animation-list>
ProgressBar 使用动画示例
<ProgressBar
android:id="@+id/progress_loading"
android:indeterminate="true"
android:indeterminateDrawable="@drawable/anim_no_available_ledaidai"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_width="162dp"
android:layout_height="125dp" />
<!-- -->
<ProgressBar
android:id="@+id/progress_loading"
android:indeterminate="true"
style="@style/progress_no_available_style"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_width="162dp"
android:layout_height="125dp" />
另外是版本判断
progressBarWaiting = (ProgressBar) mView.findViewById(R.id.progress_loading);
if (android.os.Build.VERSION.SDK_INT > 22) {//android 6.0替换clip的加载动画
final Drawable drawable = context.getApplicationContext().getResources().getDrawable(R.drawable.anim_no_available_ledaidai_v23);
progressBarWaiting.setIndeterminateDrawable(drawable);
}