anastr / SpeedView

Dynamic Speedometer and Gauge for Android. amazing, powerful, and multi shape :zap:
Apache License 2.0
1.29k stars 324 forks source link

Set Indicator Size #182

Closed Mas7erMind closed 4 years ago

Mas7erMind commented 4 years ago

Hello,

I don't find any function to specify the ImageIndicator size (width and height). As per the doc, it should be in the ImageIndicator constructor but it's not there.

to create object you cans use: ImageIndicator(context: Context, resource: Int) eysly, but we Recommend to use ImageIndicator(context: Context, resource: Int, width: Int, height: Int) to add custom width and height for indicator.

anastr commented 4 years ago

since you need a Drawable a6830d8 you have to specify the size inside your drawable itself, or add scale.

Mas7erMind commented 4 years ago

Ok. I think I didn't create my Indicator drawable properly. because it always appears in the middle of the meter.

What do you mean by: must set the center of indicator in the center of image, and the indicator towards the top,just like this one:

What should be the radius of the circle image? Do you have a sample I could start from?

Other question: is it possible to remove the transparency gradient from the TriangleIndicator?

anastr commented 4 years ago

you can start with this image

image indicator

square image, the rotate point in the center of image, the indicator in image towards up.

for TriangleIndicator no you can't.

anastr commented 4 years ago

there are other ways to import your indicator. for example you can extend Indicator class and draw your indicator just like TriangleIndicator did it. and you can remove LinearGradient if you like.

Mas7erMind commented 4 years ago

Awesome! So I implemeted my own Indicator class by just removing the LinearGradient code and it works fine... except for the indicator color. It always appear as blue. What am I doing wrong?

// Average Meter meterHashrate_avg = findViewById(R.id.meter_hashrate_avg); SimpleTriangleIndicator indicator_avg = new SimpleTriangleIndicator(contextOfApplication); indicator_avg.setColor(getResources().getColor(R.color.c_white)); indicator_avg.setWidth(40.0f); meterHashrate_avg.setIndicator(indicator_avg);

My code: http://pastie.org/p/2Ejk1JX4NJTtSS9JQic8a3

anastr commented 4 years ago

may you try to change color after attaching it to speedView:

meterHashrate_avg = findViewById(R.id.meter_hashrate_avg);
SimpleTriangleIndicator indicator_avg = new SimpleTriangleIndicator(contextOfApplication);
indicator_avg.setWidth(40.0f);
meterHashrate_avg.setIndicator(indicator_avg);
indicator_avg.setColor(getResources().getColor(R.color.c_white));
Mas7erMind commented 4 years ago

Nope. I just tried it and still the same behavior - it's still blue.

anastr commented 4 years ago

Ok, add this line at the first of draw method in your custom indicator class:

indicatorPaint.setColor(getColor());

this will fix the color until the next version.

Edit

it's better to add it at the same place where you removed LinearGradient.