Android“高级”渐变 - “拇指”职位?

发布于 2024-09-27 21:07:27 字数 509 浏览 2 评论 0原文

我正在尝试创建一个渐变绘图来描绘某物的比例。作为一般示例,假设您正在查看包含车队的列表视图。背景可以是电量计 - 我不想要平滑、宽阔的过渡。我想要一个非常紧密的过渡,并且我希望能够设置过渡发生的位置。

这就是我正在盯着的东西,但我还没有走得太远。

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

谢谢!

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>

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-10-04 21:07:27

好的,您可以这样做:

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

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);

Then just set that as your backroundDrawable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文