zoukankan      html  css  js  c++  java
  • 5月5日学习日志

    今天学习了Canvas API剪切方法合集。

    关键代码为:

    public class MyView extends View{
    
        private Bitmap mBitmap = null;
        private int limitLength = 0;     //
        private int width;
        private int heigth;
        private static final int CLIP_HEIGHT = 50;
    
        private boolean status = HIDE;//显示还是隐藏的状态,最开始为HIDE
        private static final boolean SHOW = true;//显示图片
        private static final boolean HIDE = false;//隐藏图片
    
        public MyView(Context context) {
            this(context, null);
        }
    
        public MyView(Context context, AttributeSet attrs) {
            super(context, attrs);
            mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.img_meizi);
            limitLength = width = mBitmap.getWidth();
            heigth = mBitmap.getHeight();
        }
    
        public MyView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            Region region = new Region();
            int i = 0;
            while (i * CLIP_HEIGHT <= heigth) {//计算clip的区域
                if (i % 2 == 0) {
                    region.union(new Rect(0, i * CLIP_HEIGHT, limitLength, (i + 1) * CLIP_HEIGHT));
                } else {
                    region.union(new Rect(width - limitLength, i * CLIP_HEIGHT, width, (i + 1)
                            * CLIP_HEIGHT));
                }
                i++;
            }
            canvas.clipRegion(region);
            canvas.drawBitmap(mBitmap, 0, 0, new Paint());
            if (status == HIDE) {//如果此时是隐藏
                limitLength -= 10;
                if(limitLength <= 0)
                    status=SHOW;
            } else {//如果此时是显示
                limitLength += 5;
                if(limitLength >= width)
                    status=HIDE;
            }
            invalidate();
        }
    }
  • 相关阅读:
    C51学习笔记
    Keil C51与Keil ARM共存
    keil c51笔记
    css实现三角形
    微信小程序倒计时实现
    微信小程序公共组件的引用与控制
    mac上查找nginx安装位置
    charles抓取移动端app数据
    封装react组件——三级联动
    前端基础(http协议相关篇)
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14910532.html
Copyright © 2011-2022 走看看