我试图创建一个渐变drawable来描绘某事物的比例.作为一般示例,假设您正在查看包含车队的列表视图.背景可能是一个燃料表 - 我不希望平稳,广泛的过渡.我想要一个非常紧凑的过渡,我希望能够设置转换发生的位置.
这是我正在盯着的,但我没有走得太远.
<?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>
Run Code Online (Sandbox Code Playgroud)
谢谢!
Ada*_*dam 11
好的,这是你怎么做的:
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);
Run Code Online (Sandbox Code Playgroud)
然后将其设置为backroundDrawable
| 归档时间: |
|
| 查看次数: |
6377 次 |
| 最近记录: |