我想创建一个圆形图形,它将显示我的应用程序中的一系列值.这些值可分为3类:低,中,高 - 由3种颜色表示:蓝色,绿色和红色(分别).
在此范围之上,我想显示实际测量值 - 在相关范围部分上以"拇指"的形式显示:
根据测量值,白色拇指在范围弧上的位置可以改变.
目前,我可以通过在视图的onDraw方法内的相同中心绘制3个弧来绘制3色范围:
width = (float) getWidth();
height = (float) getHeight();
float radius;
if (width > height) {
    radius = height / 3;
} else {
    radius = width / 3;
}
paint.setAntiAlias(true);
paint.setStrokeWidth(arcLineWidth);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStyle(Paint.Style.STROKE);
center_x = width / 2;
center_y = height / 1.6f;
left = center_x - radius;
float top = center_y - radius;
right = center_x + radius;
float bottom = center_y + radius;
oval.set(left, top, right, bottom);
//blue arc
paint.setColor(colorLow); …在缩放GLES20RecordingCanvas上绘制的路径具有质量,就好像它在位图中未缩放,然后向上缩放.
相比之下,如果我Canvas使用支持位图创建,然后对Canvas对象应用相同的缩放转换,我会得到更优越的位图.
 这里使用
这里使用Path.addCircle和绘制两个圆圈Canvas.scale.使用缩放绘制上圆,使用后退位图GLES20RecordingCanvas使用缩放简单绘制下圆Canvas.
一些代码:
public class TestPathRenderer extends View {
    ...
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        int measuredWidth = getMeasuredWidth();
        int measuredHeight = getMeasuredHeight();
        float distortedWidth = getDistortedWidth();
        float distortedHeight = getDistortedHeight();
        path.reset();
        path.addCircle(distortedWidth/2f, distortedHeight/2f, Math.min(distortedWidth/2f, distortedHeight/2f), Path.Direction.CW);
        bitmap = assembleNewBitmap(measuredWidth, measuredHeight);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        switch (renderMode) …在我的Android应用程序中,我想知道用户点击的点与特定的VectorDrawable组之间的距离.
我希望距离像blueVectorDrawable中的组一样:
<vector android:height="24dp" android:viewportHeight="1052.3622"
    android:viewportWidth="744.0945" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ff0000"
        android:name="blue"
        android:pathData="M182.9,349.5m-74.7,0a74.7,74.7 0,1 1,149.3 0a74.7,74.7 0,1 1,-149.3 0"
        android:strokeAlpha="1" android:strokeColor="#000000" android:strokeWidth="4.23501825"/>
    <path android:fillColor="#00ff00"
        android:name="red"
        android:pathData="M474.3,392.4a84.3,102.9 0,1 0,168.6 0a84.3,102.9 0,1 0,-168.6 0z"
        android:strokeAlpha="1" android:strokeColor="#000000" android:strokeWidth="5"/>>
</vector>
在Android中有一种直接的方法来计算这个距离吗?
android android-layout android-drawable android-graphics android-vectordrawable
我创建了一个带有自定义LinearGradient可绘制对象的搜索栏。但是,我希望能够更改每种颜色的渐变比例,这里我使用 3 种颜色,如果positions是,它们会均匀分布null。我想要的,其实是提供宽度或比于每种颜色,例如红色的变化率,并将其设置只形成0%至10%的seekBar width。
在这里,我想设置 0% 到 10% 的红色、10% - 80% 的黄色和 80% 到 100% 的红色,并且能够动态更改每种颜色的宽度值。
这是可能的,如果是,有人可以指导我如何操作吗?
我的代码
private ShapeDrawable getSeekBarGradientDrawable(int mRectWidth, int mRectHeight) {
    int[] colors = new int[] { Color.RED, Color.YELLOW, getResources().getColor(R.color.primaryButton, null)};
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int width = displayMetrics.widthPixels - (int) getResources().getDimension(R.dimen.margin_padding_size_medium);
    Shader shader = new LinearGradient(
            0,
            0,
            width,
            mRectHeight,
            colors, new float[] {0.1f,0.7f,0.2f},
            Shader.TileMode.CLAMP);
    ShapeDrawable shape = new ShapeDrawable(new RectShape());
    shape.getPaint().setShader(shader);
    return …java android android-seekbar material-design android-graphics
我想为我的项目制作一个星形。我搜索了这么多,现在我终于可以使用画布制作星形了。
但接下来我想要的对我来说真的很难。真是噩梦。我尝试并搜索过,但没有任何效果对我有用。
我想要的是星星必须由没有背景颜色的线条组成。唯一的线.. 越线..
然后一行被表达并淡出,下一行被创建并再次淡出,然后该行被创建并再次淡出,我希望它是永久的这个动作。直到我将这个活动的屏幕留给另一个。
我正在通过扩展创建自定义视图 android.view.View.
现在,我需要在低于 21 的 API 级别上绘制一个圆角矩形。Android 有一个内置的方法名称drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)in android.graphics.Canvas,但它不支持低于 21 的 API,但我需要在 API 16 上绘制它。我怎样才能做到这一点?
提前致谢
如何为调色板的样本添加透明度值?就像我将颜色(swatch.getRGB())添加到线性布局一样,它显示纯色.而且我不想使用alpha,因为它会使布局中的其他项目也变得透明.
我的代码片段:
Palette palette = Palette.from(myBitmap).generate();
Palette.Swatch swatch1 = palette.getDarkVibrantSwatch();
int color = swatch1.getRgb();
thatLayout.setBackgroundColor(color)