2013-08-20 32 views
2

我是Canvas的新手,在Android中繪圖,我只是拿了代碼from this website我設法調整了它,但是我發現很難更改邊框樣式和邊框顏色。Android drawable canvas - 更改邊框設計和顏色

我想要邊框只是一個簡單的黑色方形邊框,沒有奇特的波浪和色譜。

這是onCreate函數中的代碼,我已經設法儘量減少邊界的波浪,但仍然有小小的顛簸和轉彎。

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_main); 

    float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 }; 

    RectF inset = new RectF(6, 6, 6, 6); 
    float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 }; 

    mDrawables = new ShapeDrawable[2]; 

    mDrawables[0] = new ShapeDrawable(new RoundRectShape(outerR, inset, null)); 
    //mDrawables[0].getPaint().setShader(makeSweep()); 

    mDrawables[1] = new ShapeDrawable(new RoundRectShape(outerR, inset, innerR)); 
    //mDrawables[1].getPaint().setShader(makeLinear()); 

    PathEffect mPathEffect1 = new DiscretePathEffect(1, 1); 
    PathEffect mPathEffect2 = new CornerPathEffect(1); 

    mDrawables[0].getPaint().setPathEffect(new ComposePathEffect(mPathEffect2, mPathEffect1)); 
    RelativeLayout layout = (RelativeLayout) findViewById(R.id.myDrawing); 
    layout.setBackgroundDrawable(mDrawables[0]); 
    activity = this; 


    //mView = new DrawingView(this); 
    mView = new SignatureView(activity, null); 

    layout.addView(mView, new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 

    init(); 

    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); 
    mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL); 
} 

對不起,我知道這可能是一個簡單的任務,但我完全難住。

編輯 - 好吧,我設法使它純黑色,我剛剛刪除了mDrawables [0/1] .getPaint()行,它變成了黑色,我現在唯一的問題是使它完全直。

+0

不需要道歉,您已經研究過,調整了代碼,向我們展示了您所做的事情,並且非常具體地說明您希望實現的結果。 – 2013-08-20 10:34:58

回答

0

想通了。

對於邊框的顏色,註釋掉以下行: mDrawables[0].getPaint().setShader(makeSweep());mDrawables[1].getPaint().setShader(makeLinear());

之後,問題是DiscretePathEffect。將該行代碼更改爲: PathEffect mPathEffect1 = new DiscretePathEffect(1, 0);

顯然,DiscretePathEffect的兩個參數決定了該行如何獲得「squiggly」。