TextView作为带有textcolor最小化的进度条? [英] TextView as a progressbar with textcolor minipulation?
问题描述
我正在改善我的应用程序的用户界面.在设计中,我使用的是TextView,它将在特定时间充当进度条.ruslt应该看起来像这样:
I'm working on improving my app's UI. And in the design I'm using I have a TextView that will act as a progress bar at certain time. The ruslt should look like this :
问题在于,随着进度的变化,文本的某些部分也会改变颜色
The thing is that parts of text will change their color while the progress is changing
我在android中调查了spannablestring,如果我能找到进度所涵盖的字母,它会起作用(但我认为这不容易/准确)
I looked into spannablestring in android it would work if I can find the letters that are covered by the progress ( but I don't think this would be easy/accurate)
我现在打算做的是使用以下内容:
What I'm planning todo now is to use the following:
- 带有: 的FrameLayout
- 具有绿色文本和白色背景的背景textView.
- 前线性布局,可在进行过程中更改宽度.
- 具有绿色背景和与框架布局宽度匹配的白色文本的TextView.
- FrameLayout with :
- background textView with a green text and white background.
- front Linearlayout that changes width while progressing.
- TextView with green background and white text that matches the framelayout width.
有更好的方法吗?
推荐答案
更好的方法将要求您重写TextView类.您可以使用剪辑来拆分TextView并以不同的颜色绘制两个部分.
Much better approach would require you to override TextView class. You can use clipping, to split the TextView and draw two parts in different colors.
TextView tv = new TextView(this){
@Override
public void draw(Canvas canvas) {
int color1 = Color.WHITE;
int color2 = Color.GREEN;
canvas.save();
setTextColor(color1);
setBackgroundColor(color2);
canvas.clipRect(new Rect(0, 0, (int)(getWidth() * percent), getHeight()));
super.draw(canvas);
canvas.restore();
canvas.save();
setTextColor(color2);
setBackgroundColor(color1);
canvas.clipRect(new Rect((int)(getWidth() * percent), 0, getWidth(), getHeight()));
super.draw(canvas);
canvas.restore();
}
};
我希望你明白了
这篇关于TextView作为带有textcolor最小化的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!