2012-05-19 87 views

回答

3

繪製兩個視圖之間的一條線它簡單採取兩種觀點

 <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="#285A8C" > //Give Color As u want 
     </LinearLayout> 
+1

其實我想畫線之間兩點可能是直線,十字線 –

0

感謝之間它一個LinearLayout中每一個我得到了下面這樣的解決方案我在點擊事件上的按鈕使用三個佈局中間的佈局我用帆布畫點在畫布

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); 
    }  
    } 
} 
使用以下點擊收聽個

拿分

 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); 

        } 
        } 
        } 
     } 
} 
相關問題