2016-11-03 8 views
0

背景色が#3000000(75%透明度= B3)のカスタムビュー(Linearlayoutを拡張)を作成しています。 B3/75%透明ではありません。代わりに、私はこのビューの上に赤い線を描画したいと思い、この瞬間に、それは赤い線を引くが、トップの「黒色層」とAndroid - 背景の透明度もPaintオブジェクトに透明に設定されています

public class MyCustomObject extends LinearLayout { 

    private Paint paint; 

    public MyCustomObject(Context context) { 
     super(context); 
     init(); 
    } 

    public MyCustomObject(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     init(); 
    } 

    public MyCustomObject(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     init(); 
    } 

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 
    public MyCustomObject(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
     init(); 
    } 

    private void init() { 
     View v = View.inflate(getContext(), R.layout.custom_view, this); 
     paint = new Paint(); 
     paint.setColor(Color.RED); 
     paint.setAlpha(255); 
     paint.setStrokeWidth(50); 
     setWillNotDraw(false); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
//  super.onDraw(canvas); 
     canvas.drawLine(0,0,getWidth(),getHeight(),paint); 
     Timber.e("Drawing..."); 
    } 
} 

:私は現在持っている

振動色の赤色です。

+0

カスタム' LinearLayout'に膨張されている解決策を見つけ、そしてそれはあなたがカスタム 'View'」に描くものは何でもの前になりますキャンバス。私はそれがあなたの色を薄暗くしていると思います。 –

+0

@MikeM。どのように上に描画するだろうか?私はLinearLayoutの上に描画することを期待しています。 – Bugdr0id

答えて

0

私は `custom_view`レイアウトにあるものは何でもhere

@Override 
protected void dispatchDraw(Canvas canvas) { 
    // draw here if you want to draw behind children 
    super.dispatchDraw(canvas); 
    // draw here if you want to draw over children 
} 
+1

ああ、ええ、私はそれを考えなかった。ニースを見つける。 Jeez、私は以前にそのメソッドを利用したカスタム 'ViewGroup'を書いたこともあります。私はそれを考えなかったとは信じられません。私の悪い。申し訳ありません。 –

+1

とにかく助けてくれてありがとう:) – Bugdr0id