0

透明マスクを作成しようとしています。拡張するslidingScreenを作成しましたViewGroup。コンストラクターに次を追加します。

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
    LinearLayout roadMap = new LinearLayout(context);
    roadMap.setLayoutParams(params);
    this.addView(roadMap);  

onDispatchDraw()次に、メソッドをオーバーライドします。

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    Log.d("touchy touch", "dispatch draw called");

    canvas.drawColor(getResources().getColor(R.color.LIGHT_BLUE));
    /* recreate the blue rectangle on the canvas */
    path = new Path();
    path.moveTo(0.0f, 0.0f);        // Top Left
    path.lineTo(0.0f, 800.0f);      // Bottom Left
    path.lineTo(0.0f, 800.0f );     // Bottom Right
    path.lineTo(this.x, 0.0f);      // Top Right
    path.close(); 
    canvas.drawPath(path,paint);    
}

その結果、作成されたパスに等しい透明なマスクができました。これは問題ではありません。残念ながらロードマップは表示されません。私はオーバーライドしようとしました:

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int count = this.getChildCount();
    Log.d("children please", "count: "+count);
    for (int i = 0; i < count; i++) {
        View child = this.getChildAt(i);
        child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
        child.invalidate();
        child.bringToFront();
    }

}

それでも、アタッチしようとしている線形レイアウトは表示されません。

4

1 に答える 1