I'm having trouble getting paths to close correctly.  The problem
appears to be  consistent from API 8 (Android  2.2)  back through API
4  (Android 1.6).  Emulators exhibit  the problem, as does my 2.2
phone.

It seems that Android doesn't  "think" that a  path is closed, even
though the path starts (via path.moveTo(...)) and ends (via
path.lineTo(...))  at exactly  the same coordinates.

If I call "path.closePath()" to  ensure that the path is closed, an
errant line segment is drawn,  which indicates to me that the path is
"confused" about being open/closed, or about which point is the
beginning/ending point in the path.

A very short but complete application  is included below that
demonstrates the problem.

Any help  with what is wrong  would be appreciated.

**An image of the results is here:**  http://rebeyenterprises.com/BadPath.png

The failing code:
---------------------
**(testShape.java, in src/pkgs/testShape)**

package pkgs.testShape;
import android.app.Activity;
import android.content.Context;
import android.graphics.*;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.*;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.TextView;

@SuppressWarnings({"deprecation"})      // AbsoluteLayout is deprecated;
this quiets warnings
public class Sandbox extends Activity
{
        // For convenience - just to use the shorter Class name
        private class Params extends AbsoluteLayout.LayoutParams{Params (int
ia,int ib,int ic,int id)
        {super(ia,ib,ic,id);}}

        private class TestShapeView extends View
        {
                ShapeDrawable mDrawable;
                public TestShapeView (Context context, Paint.Style style, 
boolean
bClose)
                {
                        super(context);
                        Path path = new Path();
                        path.moveTo(50, 0);
                        path.lineTo(50,25);                                     
    // Rect: l,
t, r, b,
                        path.addArc(new RectF(  0,   0,  50,  50),   0,  90);   
// Angles:
Start, Sweep
                        path.lineTo(25,75);
                        path.addArc(new RectF( 25,  50,  75, 100), 180, -90);
                        path.lineTo(75,100);
                        path.addArc(new RectF( 50,  50, 100, 100),  90, -90);
                        path.lineTo(100,25);
                        path.addArc(new RectF( 50,   0, 100,  50),   0, -90);
                        path.lineTo(50,0);      // Closes the path - right back 
where we started
                        if (bClose)
                                path.close();   // Souldn't be necessary - path 
is closed anyway
                        mDrawable=new ShapeDrawable(new PathShape(path, 110, 
110));     // 110,
110  = H, W
                        
mDrawable.getPaint().setColor(Color.rgb(0xFF,0xFF,0xFF));
                        mDrawable.getPaint().setStyle(style);
                        mDrawable.setBounds(0, 0, 110, 110);    // Left, Top, 
Right, Bottom -
Location & size
                }
                protected void onDraw(Canvas canvas){mDrawable.draw(canvas);}
        }
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
                AbsoluteLayout layout = new AbsoluteLayout(this);       // 
Params are:
W,H,X,Y;
                TextView t;
                layout.addView(new TestShapeView(this, Paint.Style.FILL,   true 
),
                                           new Params (110, 110,   0,   10));
                t=new TextView(this);t.setText("Closed-FILL");
                        layout.addView(t,new Params (200, 30,   0,   120));
                layout.addView(new TestShapeView(this, Paint.Style.STROKE, true 
),
                                           new Params (110, 110, 200,   10));
                t=new TextView(this);t.setText("Closed-STROKE");
                        layout.addView(t,new Params (200, 30, 200,   120));
                layout.addView(new TestShapeView(this, Paint.Style.FILL,   
false),
                                           new Params (110, 110,   0, 170));
                t=new TextView(this);t.setText("NOT Closed-FILL");
                        layout.addView(t,new Params (200, 30,   0,   290));
                layout.addView(new TestShapeView(this, Paint.Style.STROKE, 
false),
                                           new Params (110, 110, 200, 170));
                t=new TextView(this);t.setText("NOT Closed-STROKE");
                        layout.addView(t,new Params (200, 30, 200,   290));
                setContentView(layout);
  }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to