-3

I want to draw a line between two views how it could possible using canvas

Devendra Shewale
  • 387
  • 1
  • 4
  • 14

2 Answers2

4

Its simple Take one linearLayout for it between two views

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#285A8C" > //Give Color As u want
        </LinearLayout>
Parag Chauhan
  • 33,908
  • 13
  • 83
  • 95
0

Thanks every one i got the following solution for this I am using three layouts the middle layout i used for canvas and draw points in that canvas on button on click event

DrawView.java

  package demo.example;

 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint; 
 import android.view.View;


public class DrawView extends View {
  Paint paint = new Paint();
   float [][] points;
    public DrawView(Context context, float[][] points2, int k) {
    super(context);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(5);
    this.points=points2;
}

@Override
 public void onDraw(Canvas canvas) {
    for(int i=0;i<points.length;i++)
    {
    canvas.drawLine(points[i][0],points[i][1],points[i][2],points[i][3], paint);
    }    
  }
 }

get points using following click listener

        public  class listener implements OnClickListener
   {
      int i;   
      listener(int k)
       {
           this.i=k;
       }
        public void onClick(View v)
        {
            for(int k=0;k<match1.length;k++)
            {   
                    if(match1[k].isClickable()==false)
                   {    
                     if(match1[k].getId()==match2[i].getId())
                     {

                        points[k][0]=match1[k].getLeft();
                             points[k]1]=match1[k].getTop()+30+linearLayout2.getTop();                       points[k][2]=200;
                         points[k][3]=match2[i].getTop()+30+linearLayout2.getTop();

                         match1[k].setCompoundDrawablesWithIntrinsicBounds(null, null,null,null);
                         match2[i].setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.bubble), null,null, null);

                         Toast.makeText(getBaseContext(),points[0]+"-"+points[1]+"-"+points[2]+"-"+points[3],Toast.LENGTH_SHORT).show();    

                     ViewGroup.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

                     drawView = new DrawView(getBaseContext(),points,k);
                                     linearLayout2.addView(drawView);

                     } 
                   }
                  }
        }
}
Devendra Shewale
  • 387
  • 1
  • 4
  • 14