Question

I am trying to create a transperancy mask. I have created a slidingScreen which extends ViewGroup. in the constructor i add:

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

I then override the onDispatchDraw() method:

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

The result is I have a transparent mask which is equal to the path created. This is not the problem. Unfortunatley roadMap is never displayed. I tried to override:

@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();
    }

}

Yet still the linearlayout i am trying to attach does not appear.

Was it helpful?

Solution

Changed to Extend FrameLayout. Removed this line:

canvas.drawColor(getResources().getColor(R.color.LIGHT_BLUE));

and then i was seeing the roadMap view!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top