我想创建一个类似于gmail app的进度条(中间进度条)来改变颜色。我可以通过保留和更新sdk / platforms中的progress_indeterminate_horizontal.xml来实现这一点。我不想使用动画(多色图像)。我想用xml实现这一点(我想使用渐变)。任何帮助将不胜感激。
提前致谢
答案 0 :(得分:4)
这是我的实现:绘制一个动画彩虹渐变。很酷,如果我自己这么说的话。它不是基于XML的,但可以做成,并且它确实使用渐变。也许它会给你一些想法。
设定:
pb = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
GradientDrawable rainbow = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED});
AnimationDrawable ad = getProgressBarAnimation();
pb.setBackgroundDrawable(ad);
动画:
private AnimationDrawable getProgressBarAnimation(){
GradientDrawable rainbow1 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] {Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW});
GradientDrawable rainbow2 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] { Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN});
GradientDrawable rainbow3 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN });
GradientDrawable rainbow4 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] { Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE });
GradientDrawable rainbow5 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] { Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA });
GradientDrawable rainbow6 = new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] {Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED });
GradientDrawable[] gds = new GradientDrawable[] {rainbow1, rainbow2, rainbow3, rainbow4, rainbow5, rainbow6};
AnimationDrawable animation = new AnimationDrawable();
for (GradientDrawable gd : gds){
animation.addFrame(gd, 100);
}
animation.setOneShot(false);
return animation;
}
科特林
设定:
val ad = getProgressBarAnimation()
progressBar.background = ad
动画:
fun getProgressBarAnimation(): AnimationDrawable {
val rainbow1 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW))
val rainbow2 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN))
val rainbow3 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE, Color.CYAN))
val rainbow4 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.BLUE))
val rainbow5 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA))
val rainbow6 = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
intArrayOf(Color.MAGENTA, Color.BLUE, Color.CYAN, Color.GREEN, Color.YELLOW, Color.RED))
val gds = arrayListOf(rainbow1, rainbow2, rainbow3, rainbow4, rainbow5, rainbow6)
val animation = AnimationDrawable()
for (gd in gds) {
animation.addFrame(gd, 100)
}
animation.isOneShot = false;
return animation;
}
答案 1 :(得分:1)
This is what you are looking for.在您的项目中添加此库,您将能够使用它。
然后您就可以将它用作普通的处理栏。例如:
private SmoothProgressBar mProgressBar;
OnCreate中:
mProgressBar = (SmoothProgressBar) findViewById(R.id.progressbar);
mProgressBar.progressiveStart();
的onPause:
mProgressBar.progressiveStop();
答案 2 :(得分:0)
如果您使用的是 material design library,那么制作线性进度条 contiguous
可能就是您想要的。
app:indeterminateAnimationType
setIndeterminateAnimationType()
有关详细信息,请参阅 here。