程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> drawpath-只有20行代碼!請大神幫忙看看,為什麼drawPath( )會失效,但drawCircle( )卻管用

drawpath-只有20行代碼!請大神幫忙看看,為什麼drawPath( )會失效,但drawCircle( )卻管用

編輯:編程綜合問答
只有20行代碼!請大神幫忙看看,為什麼drawPath( )會失效,但drawCircle( )卻管用

public class Hehe extends View {
Path p;
Paint p1;
public Hehe(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
p=new Path();//定義一個路徑
p.moveTo(40, 40);
p.lineTo(80, 90);
p1=new Paint();//定義一支畫筆
p1.setStrokeWidth(3);
p1.setColor(Color.BLACK);
}

public void onDraw( Canvas canvas)
{
    canvas.drawCircle(20, 20, 10, p1);//畫一個圓。能畫出來。
    canvas.drawPath(p,p1);//通過用路徑的方式,畫一條直線。畫不出來。![CSDN移動問答][1]
}

}

最佳回答:


在初始化path那裡加上一句

p.close();

試試

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved