本文介绍了Android的"高级"渐变 - “拇指”的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个渐变绘制描绘的东西比。作为一个普通的例子,假设你在看含轿车组成的车队列表视图。背景可能是燃油表 - 我不希望有一个平稳,宽过渡。我想一个很紧的转变,我希望能够设置在那里的转换发生。
I am trying to create a gradient drawable to depict a ratio of something. As a general example, lets say you were looking at a listview containing a fleet of cars. The background could be a fuel gauge - I don't want a smooth, wide transition. I want a very tight transition, and I want to be able to set where that transition takes place.
下面就是我凝视着,但我没有得到很远。
Here's what I'm staring with, but I'm not getting very far.
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#D2E3D3"
android:endColor="#E6E6E3"
android:angle="0"
/>
<corners android:radius="0dp" />
</shape>
谢谢!
推荐答案
好吧,这里是你如何能做到这一点:
Ok, here's how you can do it:
ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
LinearGradient lg = new LinearGradient(0, 0, width, height,
new int[]{Color.GREEN, Color.GREEN, Color.WHITE, Color.WHITE},
new float[]{0,0.5f,.55f,1}, Shader.TileMode.REPEAT);
return lg;
}
};
PaintDrawable p=new PaintDrawable();
p.setShape(new RectShape());
p.setShaderFactory(sf);
然后,只需设置为您backroundDrawable
Then just set that as your backroundDrawable
这篇关于Android的&QUOT;高级&QUOT;渐变 - “拇指”的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!