画一个view覆盖在当前屏幕上

    private void drawRoundCorner() {
            com.android.internal.widget.RoundCorner mRoundCorner = new com.android.internal.widget.RoundCorner(mContext);
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
            lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
            lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
            if (ActivityManager.isHighEndGfx()) {
                lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
                lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
            }
            lp.format = PixelFormat.TRANSLUCENT;
            lp.setTitle("RoundCorner");
            WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
            lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
            wm.addView(mRoundCorner, lp);
    }

效果如下图
这里写图片描述

package com.android.internal.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.content.res.Configuration;

@SuppressLint("DrawAllocation")
public class RoundCorner extends View {

    Paint mPaint;
    //int mWidth, mHeight;

    public RoundCorner(Context context) {
        super(context);
        mPaint = new Paint();
        /*android.util.DisplayMetrics dm = new android.util.DisplayMetrics();
        android.view.WindowManager wm = (android.view.WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        mWidth = dm.widthPixels;
        mHeight = dm.heightPixels;*/
    }

    public RoundCorner(Context context, AttributeSet attrs) {
        this(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setAntiAlias(true);
        android.view.WindowManager wm = (android.view.WindowManager) getContext().getSystemService(android.content.Context.WINDOW_SERVICE);
        int rotation = wm.getDefaultDisplay().getRotation();
        int resid = 0;
        switch (rotation) {
            case android.view.Surface.ROTATION_0://
            case android.view.Surface.ROTATION_180://
                resid = com.android.internal.R.drawable.zzz_round_corner;
                break;
            case android.view.Surface.ROTATION_90://left
                resid = com.android.internal.R.drawable.zzz_round_corner_land;
                break;
            case android.view.Surface.ROTATION_270://right
                resid = com.android.internal.R.drawable.zzz_round_corner_empty;
                break;
        }
        Configuration mConfiguration = this.getResources().getConfiguration();
        int ori = mConfiguration.orientation ; 
        //android.util.Log.i("orientation", "now = " + ori);
        if(ori == mConfiguration.ORIENTATION_LANDSCAPE){
            canvas.drawBitmap(((BitmapDrawable) getContext().getResources().getDrawable(resid)).getBitmap(), null, new Rect(0, 0, 1280, 640), mPaint);
        }else{
            canvas.drawBitmap(((BitmapDrawable) getContext().getResources().getDrawable(resid)).getBitmap(), null, new Rect(0, 0, 640, 1280), mPaint);
        }

    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值