ask*_*ndz 12 animation android progress-bar
我正在尝试创建一个进度条,当条形图水平前进时,它会在垂直旋转中动画.我成功地使用我的进度drawable作为drawable via:
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/custom_progress"
android:layout_marginRight="5dp" />
Run Code Online (Sandbox Code Playgroud)
这是我的绘画:

但是我希望它有一个微妙的滚动效果作为其进展.所以它看起来像垂直线向后移动sorta.你跟着?任何帮助深表感谢.谢谢.
编辑:我尝试创建一个动画列表作为我的进度可绘制但我仍然无法看到动画.动画列表可以位于进度项的剪辑内吗?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background" android:drawable="@drawable/gutter"></item>
<item android:id="@android:id/progress">
<clip>
<animation-list android:oneshot="false">
<item android:drawable="@drawable/progress_bar_animate" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate2" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate3" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate4" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate5" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate6" android:duration="100" />
<item android:drawable="@drawable/progress_bar_animate7" android:duration="100" />
</animation-list>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
use*_*737 10
雅虎 最后!工作!(但!!!!会因大图像而导致内存泄漏.已在下面的帖子中修复)
此代码获取图块图片(tile1),重复它(TileMode.REPEAT),制作移位动画(10个片段),在动画集中添加它.

private void initAnimation() {
// R.drawable.tile1 is PNG
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.tile1);
AnimationDrawable shiftedAnimation = getAnimation(b);
// R.id.img_3 is ImageView in my application
View v = findViewById(R.id.img_3);
v.setBackground(shiftedAnimation);
shiftedAnimation.start();
}
private Bitmap getShiftedBitmap(Bitmap bitmap, int shiftX) {
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Canvas newBitmapCanvas = new Canvas(newBitmap);
Rect srcRect1 = new Rect(shiftX, 0, bitmap.getWidth(), bitmap.getHeight());
Rect destRect1 = new Rect(srcRect1);
destRect1.offset(-shiftX, 0);
newBitmapCanvas.drawBitmap(bitmap, srcRect1, destRect1, null);
Rect srcRect2 = new Rect(0, 0, shiftX, bitmap.getHeight());
Rect destRect2 = new Rect(srcRect2);
destRect2.offset(bitmap.getWidth() - shiftX, 0);
newBitmapCanvas.drawBitmap(bitmap, srcRect2, destRect2, null);
return newBitmap;
}
private List<Bitmap> getShiftedBitmaps(Bitmap bitmap) {
List<Bitmap> shiftedBitmaps = new ArrayList<Bitmap>();
int fragments = 10;
int shiftLength = bitmap.getWidth() / fragments;
for(int i = 0 ; i < fragments; ++i){
shiftedBitmaps.add( getShiftedBitmap(bitmap,shiftLength * i));
}
return shiftedBitmaps;
}
private AnimationDrawable getAnimation(Bitmap bitmap) {
AnimationDrawable animation = new AnimationDrawable();
animation.setOneShot(false);
List<Bitmap> shiftedBitmaps = getShiftedBitmaps(bitmap);
int duration = 50;
for(Bitmap image: shiftedBitmaps){
BitmapDrawable navigationBackground = new BitmapDrawable(getResources(), image);
navigationBackground.setTileModeX(TileMode.REPEAT);
animation.addFrame(navigationBackground, duration);
}
return animation;
}
Run Code Online (Sandbox Code Playgroud)
我不认为这可以按照我想象的方式完成。原因是我无法引用动画列表(此时它是一个 ClipDrawable),并将其转换为 AnimateDrawable,这是必要的,以便我可以以编程方式启动动画。还需要将其包含在 Clip 元素中,因为这是 ProgressBar 屏蔽图像的方式,因此它仅在进度时显示图像的一部分。
除了使用 ImageView 伪造我自己的进度条并对其进行动画处理之外,我没有看到针对此特定 ProgressBar 的其他方法。
| 归档时间: |
|
| 查看次数: |
24941 次 |
| 最近记录: |