0

我正在尝试创建一个透明蒙版。我创建了一个可以扩展的滑动屏幕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

0

更改为扩展 FrameLayout。删除了这一行:

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

然后我看到了路线图视图!

于 2013-09-19T09:01:41.833 回答