自定义广告

https://github.com/wanglianghai/FunctionAdvertising
注意invalidate():不会清空原来的视图,so mProgress初始值小些.
//mBoundSize是圆两边的边界和,一边就是mBoundSize/2
mBoundPaint.setStrokeWidth(mBoundSize);

//这个方法快第一个运行,在构造方法前
    {
        mTextPaint.setTextAlign(Paint.Align.CENTER);
        mCirclePaint.setColor(Color.YELLOW);
        mBoundPaint.setStyle(Paint.Style.STROKE);
        mBoundPaint.setColor(Color.GREEN);
    }

1.动画改变边界的进度可以用计算器改变progress的值

private int mProgress = 0;
mBoundPath.arcTo(leftBound, mTopBound, rightBound, mBottomBound, -90, mProgress, true);

1.1计时器

new CountDownTimer(5000, 30) {
            private static final String TAG = "CountDownTimer";
//millisUntilFinished剩余时间
            @Override
            public void onTick(long millisUntilFinished) {
                mProgress = (int) (360 * (5000 - millisUntilFinished) / 5000);
//                Log.i(TAG, "onTick: " + millisUntilFinished);
                invalidate();
            }

            @Override
            public void onFinish() {
                //finish时millisUntilFinished  > 0, 有空隙
                mProgress = -90;
                invalidate();
            }
        }.start();

2.自定义属性
在value中attrs.xml中(没有就新建)

<declare-styleable name="AdvertisingView">
        <attr name="text_string" format="string"/>
        <attr name="text_size" format="dimension"/>
        <attr name="view_size" format="dimension"/>
        <attr name="bound_size" format="dimension"/>
        <attr name="text_color" format="color"/>
        <attr name="circle_color" format="color"/>
</declare-styleable>

2.1
在布局中

xmlns:app="http://schemas.android.com/apk/res-auto"
app:text_size="12sp"
app:text_string="跳过"
app:bound_size="0dp"
app:view_size="25dp"

2.2
在view代码中获取数据

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AdvertisingView);
        mString = a.getString(R.styleable.AdvertisingView_text_string);
        mTextSize = a.getDimension(R.styleable.AdvertisingView_text_size, 12.0f);
        mWidth = a.getDimension(R.styleable.AdvertisingView_view_size, 20);
        mBoundSize = a.getDimension(R.styleable.AdvertisingView_bound_size, 12);
        a.recycle();

3.用接口前判断下是否是空,出问题时看修改方法前看下方法那些地方有用到Ctrl+B
3.1
设置dialog全屏
设置style

<style name="DialogFullScreen">
    <item name="android:widowFullSreen">true</item>
    <item name="android:widowNoTitle">true</item>
</style>

继承dialog

class AdvertisingDialog extends Dialog {
    AdvertisingDialog(Context context) {
        super(context, R.style.DialogFullScreen);
    }
}

添加退出dialog动画

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000">

    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

style.xml下

<style name="AddDialogAnimator parent="@android:style/Animation>
<item name = "android:windowExitAnimation>@anim/exit_down</item>
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值