下面列出了android.view.animation.TranslateAnimation#setDuration() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_capture);
scanPreview = (SurfaceView) findViewById(R.id.capture_preview);
scanContainer = (RelativeLayout) findViewById(R.id.capture_container);
scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
scanLine = (ImageView) findViewById(R.id.capture_scan_line);
inactivityTimer = new InactivityTimer(this);
beepManager = new BeepManager(this);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
0.9f);
animation.setDuration(4500);
animation.setRepeatCount(-1);
animation.setRepeatMode(Animation.RESTART);
scanLine.startAnimation(animation);
}
@SuppressLint("NewApi")
public static void translateY(final View view, float fromY, float toY, long duration)
{
if (Build.VERSION.SDK_INT >= 12)
{
if (duration == 0)
view.setTranslationY(toY);
else
view.animate().translationY(toY).setDuration(duration).start();
}
else
{
TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
translate.setDuration(duration);
translate.setFillEnabled(true);
translate.setFillBefore(true);
translate.setFillAfter(true);
addAnimation(view, translate);
}
}
/**
* true the underline control to the click position
* @param position
*/
public void changeWeekDay(int position){
float offset = (float) (getWidth() - getPaddingLeft() - getPaddingRight()) / 7;
LinearLayout.LayoutParams params = (LayoutParams) iv_underline.getLayoutParams();
params.width = (int) offset;
iv_underline.setLayoutParams(params);
TranslateAnimation animation = new TranslateAnimation(
offset * currentPosition ,position * offset,0,0);
animation.setFillAfter(true);
animation.setFillEnabled(true);
animation.setDuration(300);
iv_underline.startAnimation(animation);
setTabTextStyle(currentPosition,false);
setTabTextStyle(position,true);
currentPosition = position;
}
/**
* Translates the adapter in Y
*
* @param of offset in px
*/
public void translateHeader(float of) {
float ofCalculated = of * mScrollMultiplier;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && of < mHeader.getHeight()) {
mHeader.setTranslationY(ofCalculated);
} else if (of < mHeader.getHeight()) {
TranslateAnimation anim = new TranslateAnimation(0, 0, ofCalculated, ofCalculated);
anim.setFillAfter(true);
anim.setDuration(0);
mHeader.startAnimation(anim);
}
mHeader.setClipY(Math.round(ofCalculated));
if (mParallaxScroll != null) {
final RecyclerView.ViewHolder holder = mRecyclerView.findViewHolderForAdapterPosition(0);
float left;
if (holder != null) {
left = Math.min(1, ((ofCalculated) / (mHeader.getHeight() * mScrollMultiplier)));
}else {
left = 1;
}
mParallaxScroll.onParallaxScroll(left, of, mHeader);
}
}
private void startAppearAnimOnTop(final View view) {
final TranslateAnimation showAnim = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1f,
Animation.RELATIVE_TO_SELF, 0.0f);
showAnim.setDuration(250);
view.startAnimation(showAnim);
}
private void startAniation(View v) {
TranslateAnimation animation = new TranslateAnimation(
currentIndicatorLeft, v.getLeft(), 0f, 0f);
animation.setInterpolator(new LinearInterpolator());
animation.setDuration(100);
animation.setFillAfter(true);
iv_nav_indicator.setAnimation(animation);
iv_nav_indicator.startAnimation(animation);
currentIndicatorLeft = v.getLeft();
/*animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.i(TAG, "enter onAnimationStart");
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.i(TAG, "enter onAnimationEnd");
}
});*/
}
private void startAnim() {
this.isPlayingAnim = true;
int distance = this.mLine.getMeasuredWidth() - this.mCircle.getMeasuredWidth();
TranslateAnimation anim = new TranslateAnimation(0.0f, this.isChecked ? (float) (-distance) : (float) distance, 0.0f, 0.0f);
anim.setDuration(40);
anim.setFillAfter(false);
anim.setAnimationListener(this);
this.mCircle.startAnimation(anim);
}
public EditTextShakeHelper(Context context) {
// 初始化振动器
shakeVibrator = (Vibrator) context
.getSystemService(Service.VIBRATOR_SERVICE);
// 初始化震动动画
shakeAnimation = new TranslateAnimation(0, 10, 0, 0);
shakeAnimation.setDuration(300);
cycleInterpolator = new CycleInterpolator(8);
shakeAnimation.setInterpolator(cycleInterpolator);
}
/**
* 展示控件
*/
public void show() {
builder();
setSheetItems();
AlphaAnimation animation1 = new AlphaAnimation(0.3f, 1.0f);
animation1.setDuration(200);
TranslateAnimation animation = new TranslateAnimation(0, 0, HEIGHT, 0);
animation.setDuration(320);
rootLayout.startAnimation(animation1);
parentLayout.startAnimation(animation);
showAtLocation(((ViewGroup)(((Activity) context).findViewById(android.R.id.content))).getChildAt(0), Gravity.BOTTOM, 0, 0);
}
private void initAnims() {
animShow = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 0);
animShow.setDuration(300);
animHide = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1);
animHide.setDuration(300);
}
private void initAnim() {
animShow = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 0);
animShow.setDuration(300);
animHide = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1);
animHide.setDuration(300);
}
public BottomUpWindow show(View parent) {
this.showAtLocation(parent, Gravity.BOTTOM
| Gravity.CENTER_HORIZONTAL, 0, 0);
ll_panel.setVisibility(View.VISIBLE);
//动画
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0);
animation.setDuration(200);
ll_panel.startAnimation(animation);
if (associationView != null) {
associationView.onShow();
}
return this;
}
public void hideToFromView() {
if (vFrom != null) {
AlphaAnimation animAlpha = new AlphaAnimation(1, 0);
animAlpha.setDuration(AnimationDuration);
vMask.startAnimation(animAlpha);
int x = 0;
int y = (screenHeight - statusBarHeight - screenWidth) / 2
+ statusBarHeight;
int[] location = new int[2];
vFrom.getLocationInWindow(location);
int toX = location[0];
int toY = location[1];
float scale = (float) vFrom.getWidth()
/ (float) UIUtil.getScreenWidth();
ScaleAnimation animScale = new ScaleAnimation(1, scale, 1, scale);
animScale.setDuration(AnimationDuration);
TranslateAnimation animTrans = new TranslateAnimation(0, toX - x,
0, toY - y);
animTrans.setDuration(AnimationDuration);
AnimationSet animSet = new AnimationSet(true);
animSet.addAnimation(animScale);
animSet.addAnimation(animTrans);
flImages.startAnimation(animSet);
postDelayed(new Runnable() {
@Override
public void run() {
setVisibility(View.GONE);
}
}, AnimationDuration);
} else {
setVisibility(View.GONE);
}
}
private void showLoadingPage(WidgetConfigVO configVO, EBrowserWindow curWind) {
LayoutInflater layoutInflater = LayoutInflater.from(mContext);
inflate = (LinearLayout) layoutInflater.inflate(EUExUtil.getResLayoutID("platform_mp_window_middle_loadding"), null);
inflate.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
ImageView platform_mp_loadding_close = (ImageView) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_close"));
TextView platformName = (TextView) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_iconname"));
platformName.setText(configVO.widgetName);
platform_mp_loadding_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//回调前端方法去关闭子应用
callBackPluginJs("uexWidget.cbCloseLoading", "0");
mBrwView.removeView(inflate);
}
});
ImageButton platform_mp_loadding_icon = (ImageButton) inflate.findViewById(EUExUtil.getResIdID("platform_mp_loadding_icon"));
curWind.showButtonIcon(platform_mp_loadding_icon, configVO.appIcon);
TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
anim.setDuration(500);
inflate.startAnimation(anim);
ViewGroup.LayoutParams param=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mBrwView.addView(inflate, -1,param);
Log.e("TAG", "显示过度界面完成================");
}
@Override
protected void translatePreICS(View view, float offset) {
TranslateAnimation ta = new TranslateAnimation(0, 0, offset, offset);
ta.setDuration(0);
ta.setFillAfter(true);
view.setAnimation(ta);
ta.start();
}
public EditTextShakeHelper(Context context) {
// 初始化振动器
shakeVibrator = (Vibrator) context
.getSystemService(Service.VIBRATOR_SERVICE);
// 初始化震动动画
shakeAnimation = new TranslateAnimation(0, 10, 0, 0);
shakeAnimation.setDuration(300);
cycleInterpolator = new CycleInterpolator(8);
shakeAnimation.setInterpolator(cycleInterpolator);
}
public void animation() {
TranslateAnimation ta = new TranslateAnimation(0, 0, inner.getTop(),
normal.top);
ta.setDuration(200);
inner.startAnimation(ta);
inner.layout(normal.left, normal.top, normal.right, normal.bottom);
normal.setEmpty();
}
/**
* 位移 Translate
*/
public static Animation getTranslateAnimation(float fromXDelta,
float toXDelta, float fromYDelta, float toYDelta,
long durationMillis) {
TranslateAnimation translate = new TranslateAnimation(fromXDelta,
toXDelta, fromYDelta, toYDelta);
translate.setDuration(durationMillis);
translate.setFillAfter(true);
return translate;
}
private TranslateAnimation moveAnimationY(int overY){
TranslateAnimation animation = new TranslateAnimation(0, 0, cardSize * overY, 0);
animation.setDuration(120 * Math.abs(overY));
return animation;
}
private TranslateAnimation getTranslateAnimator(float targetX, float targetY) {
TranslateAnimation translateAnimation = new TranslateAnimation(1, 0.0f, 0, targetX, 1, 0.0f, 0, targetY);
translateAnimation.setDuration(ANIM_TIME);
translateAnimation.setFillAfter(true);
return translateAnimation;
}