Android 安卓;“高级”;梯度-';拇指';位置?

Android 安卓;“高级”;梯度-';拇指';位置?,android,gradient,Android,Gradient,我正在尝试创建一个可以描绘某个比率的渐变。作为一般示例,假设您正在查看包含车队的listview。背景可能是一个燃油表-我不想要一个平稳,广泛的过渡。我想要一个非常紧密的过渡,我想要能够设置过渡发生的位置 这是我要看的,但我没走多远 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="r

我正在尝试创建一个可以描绘某个比率的渐变。作为一般示例,假设您正在查看包含车队的listview。背景可能是一个燃油表-我不想要一个平稳,广泛的过渡。我想要一个非常紧密的过渡,我想要能够设置过渡发生的位置

这是我要看的,但我没走多远

<?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>


谢谢

好的,下面是你可以做到的:

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);
然后将其设置为可回溯的