如何在显示自定义视图时调暗背景视图

时间:2011-09-28 14:13:33

标签: android layout

自定义视图显示时,如何调暗背景?在我的活动中,我有相对布局,背景中有一些照片。当用户做一些动作时 - FrameLayout出现在屏幕的中心 - 然后我想让它像对话框一样 - 在framelayout下调暗一切。

我怎样才能实现这一目标?

1 个答案:

答案 0 :(得分:8)

添加此视图..它会帮助你..

public class TransparentPanel extends LinearLayout {
    private Paint innerPaint;

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

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

    private void init() {
        innerPaint = new Paint();
        innerPaint.setARGB(180, 75, 75, 75);
    }

    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {

        RectF drawRect = new RectF();
        drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

        canvas.drawRoundRect(drawRect, 5, 5, innerPaint);

        super.dispatchDraw(canvas);
    }
}