这次是需求有点无语,不过还是做出来了,效果如下,这回要讲讲,有点复杂,以后自己估计都忘了,记录一下--!
动画类AnimalUtul:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
public
class
AnimalUtul {
private
AnimatorSet mAnimatorSet;
RelativeLayout rl_parent;
private
ImageView iv_logo;
private
float
mLogoY;
private
Context context;
private
long
starttime =
1500
;
public
long
getStarttime() {
return
starttime;
}
public
void
setStarttime(
long
starttime) {
this
.starttime = starttime;
}
public
AnimalUtul(Context context, RelativeLayout layout, ImageView logo) {
iv_logo = logo;
rl_parent = layout;
this
.context = context;
iv_logo.postDelayed(
new
Runnable() {
@Override
public
void
run() {
if
(mLogoY ==
0
) {
mLogoY = ViewHelper.getY(iv_logo);
}
playLogoInAnim();
}
}, starttime);
iv_logo.postDelayed(
new
Runnable() {
@Override
public
void
run() {
playInAnim();
}
}, starttime);
}
public
void
playInAnim() {
rl_parent.setVisibility(View.VISIBLE);
AnimatorSet mAnimatorSet;
ObjectAnimator anim3 = ObjectAnimator.ofFloat(rl_parent,
"y"
,
DisplayUtil.getDisplayheightPixels(context),
DisplayUtil.dip2px(context,
160
));
mAnimatorSet =
new
AnimatorSet();
mAnimatorSet.play(anim3);
mAnimatorSet.setDuration(
1000
);
mAnimatorSet.start();
}
private
void
playLogoInAnim() {
ObjectAnimator anim1 = ObjectAnimator.ofFloat(iv_logo,
"scaleX"
,
1
.0f,
0
.5f);
ObjectAnimator anim2 = ObjectAnimator.ofFloat(iv_logo,
"scaleY"
,
1
.0f,
0
.5f);
ObjectAnimator anim3 = ObjectAnimator.ofFloat(iv_logo,
"y"
, mLogoY,
DisplayUtil.dip2px(context,
15
));
if
(mAnimatorSet !=
null
&& mAnimatorSet.isRunning()) {
mAnimatorSet.cancel();
mAnimatorSet =
null
;
}
mAnimatorSet =
new
AnimatorSet();
mAnimatorSet.play(anim1).with(anim2);
mAnimatorSet.play(anim2).with(anim3);
mAnimatorSet.setDuration(
1000
);
mAnimatorSet.start();
}
}
|
适配屏幕高度类DisplayUtil:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
public
class
DisplayUtil {
/** 屏幕宽度 */
private
static
int
DisplayWidthPixels =
0
;
/** 屏幕高度 */
private
static
int
DisplayheightPixels =
0
;
/**
* 获取屏幕参数
* @param context
*/
private
static
void
getDisplayMetrics(Context context) {
DisplayMetrics dm =
new
DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
// 宽度
DisplayWidthPixels = dm.widthPixels;
// 高度
DisplayheightPixels = dm.heightPixels;
}
/**
* 获取屏幕宽度
* @param context
* @return
*/
public
static
int
getDisplayWidthPixels(Context context) {
if
(context ==
null
) {
return
-
1
;
}
if
(DisplayWidthPixels ==
0
) {
getDisplayMetrics(context);
}
return
DisplayWidthPixels;
}
/**
* 获取屏幕高度
* @param context
* @return
*/
public
static
int
getDisplayheightPixels(Context context) {
if
(context ==
null
) {
return
-
1
;
}
if
(DisplayheightPixels ==
0
) {
getDisplayMetrics(context);
}
return
DisplayheightPixels;
}
/**
* 将px值转换为dip或dp值
*
* @param pxValue
* @return
*/
public
static
int
px2dip(Context context,
float
pxValue) {
final
float
scale = context.getResources().getDisplayMetrics().density;
return
(
int
) (pxValue / scale +
0
.5f);
}
/**
* 将dip或dp值转换为px值
*
* @param dipValue
* @return
*/
public
static
int
dip2px(Context context,
float
dipValue) {
final
float
scale = context.getResources().getDisplayMetrics().density;
return
(
int
) (dipValue * scale +
0
.5f);
}
/**
* 将px值转换为sp值
*
* @param pxValue
* @return
*/
public
static
int
px2sp(Context context,
float
pxValue) {
final
float
fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return
(
int
) (pxValue / fontScale +
0
.5f);
}
/**
* 将sp值转换为px值
* @param spValue
* @return
*/
public
static
int
sp2px(Context context,
float
spValue) {
final
float
fontScale = context.getResources().getDisplayMetrics().scaledDensity;
return
(
int
) (spValue * fontScale +
0
.5f);
}
}
|
调用方法:new AnimalUtul(this,出现的layout,logo图片);
唉~好累~天天写这些--!
本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1673192,如需转载请自行联系原作者