View的透明度,设置view透明度setAlpha 及 Alpha透明度渐变动画

> android设置view透明度的效果的三种方式:
1.android:background="#ff6495ED"> 
2.textView.setBackgroundColor(Color.TRANSPARENT);
3.convertView.getBackground().setAlpha(80);

> Android透明度数值对比:
透明度    数值
100%    FF
95%    F2
90%    E6
85%    D9
80%    CC
75%    BF
70%    B3
65%    A6
60%    99
55%    8C
50%    80
45%    73
40%    66
35%    59
30%    4D
25%    40
20%    33
15%    26
10%    1A
5%    0D
0%    00

> view.setAlpha()和 view.getBackground().setAlpha()的区别
 传参:setAlpha()传参是0-1的foalt数 而 getBackground().setAlpha()传入的是0-255的int数;(最终它们都会转化成16进制,setAlpha()传入的参数会先*255转化为int型)
 效果:setAlpha()是对整个view的透明度(包括它的子view)进行设置,setAlpha(0)时view和子view就会消失;
getBackground().setAlpha()是对View的背景透明度设置:getBackground().setAlpha(0)时背景为全透明。

> View设置Alpha值,及动画效果
subView.getBackground().setAlpha(64);
private void startGradientAlphaAnimator(View view) { // ImageView的alpha渐变
        mAlphaAnimation = ObjectAnimator.ofFloat(view, "alpha", 1f, 0.15f);
        mAlphaAnimation.setDuration(1000);
        mAlphaAnimation.setRepeatCount(0);
        mAlphaAnimation.setRepeatMode(ValueAnimator.RESTART);
        mAlphaAnimation.setStartDelay(0);
        mAlphaAnimation.setInterpolator(new LinearInterpolator());
        mAlphaAnimation.start();
    }

private void startAlphaAnimator(View view) { // ImageView的alpha渐变后再变回来
        mAlphaAnimation = ObjectAnimator.ofFloat(view, "alpha", 1f, 1f);
        mAlphaAnimation.setDuration(0);
        mAlphaAnimation.setRepeatCount(0);
        mAlphaAnimation.setRepeatMode(ValueAnimator.RESTART);
        mAlphaAnimation.setStartDelay(0);
        mAlphaAnimation.setInterpolator(new LinearInterpolator());
        mAlphaAnimation.start();
    }

public void stopAlphaAnimator() {
        if (mAlphaAnimation != null && mAlphaAnimation.isRunning()) {
            mAlphaAnimation.cancel();
        }
    }

AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.2f);
        //设置动画持续时长
        alphaAnimation.setDuration(3000);
        //设置动画结束之后的状态是否是动画的最终状态,true,表示是保持动画结束时的最终状态
        alphaAnimation.setFillAfter(true);
        //设置动画结束之后的状态是否是动画开始时的状态,true,表示是保持动画开始时的状态
        alphaAnimation.setFillBefore(true);
        //设置动画的重复模式:反转REVERSE和重新开始RESTART
        alphaAnimation.setRepeatMode(AlphaAnimation.REVERSE);
        //设置动画播放次数
        alphaAnimation.setRepeatCount(AlphaAnimation.INFINITE);
        //开始动画
        mIvImg.startAnimation(alphaAnimation);
        //清除动画
        mIvImg.clearAnimation();
        //同样cancel()也能取消掉动画
        alphaAnimation.cancel();

> 加载Assert皮肤资源到文件夹下
private void loadAssertToFile() { // 加载Assert皮肤资源到文件夹下
        AssetManager assets = AppContext.getInstance().getAssets();
        try {
            InputStream is = assets.open("hello.txt");
            File file = new File("/data/data/" + AppContext.getInstance().getPackageName() + "/databases");
            if (!file.exists()) {
                file.mkdirs();
            }
            FileOutputStream fos = new FileOutputStream(new File(file, "hello.txt"));
            byte[] buff = new byte[1024 * 8];
            int len = -1;
            while ((len = is.read(buff)) != -1) {
                fos.write(buff, 0, len);
            }
            fos.close();
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值