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>