Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dashed lines show in Graphical Layout but not on devices

I am using paint to draw a dashed line in android.

dashed.setPathEffect(new DashPathEffect(new float[] { 5, 5 }, 0));

During development, everything shows up fine in the Graphical Layout view. But when I plugin a real device, the device shows a solid line. At first I thought it was because my devices were all LG. Then I tested on a Samsung S4: same problem. Does anyone know how to fix this discrepancy? It makes no sense that the Graphical Layout is saying one thing and yet no actual device agrees with it. Any advice?

like image 241
Cote Mounyo Avatar asked Jul 22 '13 18:07

Cote Mounyo


Video Answer


2 Answers

disable hardware acceleration might be not best way, try this from here :

Path baseline = new Path();
baseline.moveTo(0, 0);
baseline.lineTo(100, 0);
canvas.drawPath(baseline, paint);
like image 198
Nokuap Avatar answered Sep 24 '22 08:09

Nokuap


See if turning off the hardware acceleration for the view helps:

@Override
public static void disableHardwareRendering(View v) {

    v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

}

From Android developers page on Hardware Acceleration:

Use a software layer type to force a view to be rendered in software. If a view that is hardware accelerated (for instance, if your whole application is hardware acclerated), is having rendering problems, this is an easy way to work around limitations of the hardware rendering pipeline.

Some more information about this issue on code.google: Link.

like image 24
Vikram Avatar answered Sep 25 '22 08:09

Vikram