显示自定义视图时如何调暗背景视图 [英] How can I dim the backround view when a custom View is displayed

查看:80
本文介绍了显示自定义视图时如何调暗背景视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示自定义视图时如何调暗背景?在我的活动中,我有相对布局,背景中有一些照片.当用户执行一些操作时-FrameLayout出现在屏幕中央-然后我要使其像对话框一样操作-使framelayout下的所有内容变暗.

How can I dim my background when custom View is showing? In my Activity I have Relative Layout with some photo in background. When user do some action - FrameLayout appears in center of screen - and then I want make it to act like dialog - dim everything under framelayout.

我该如何实现?

推荐答案

在此视图上添加此视图.它将为您提供帮助.

add this view over it.. it ll help you..

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

这篇关于显示自定义视图时如何调暗背景视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆