本文整理汇总了Java中android.view.animation.TranslateAnimation类的典型用法代码示例。如果您正苦于以下问题:Java TranslateAnimation类的具体用法?Java TranslateAnimation怎么用?Java TranslateAnimation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TranslateAnimation类属于android.view.animation包,在下文中一共展示了TranslateAnimation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ScanManager
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 用于启动照相机扫描二维码,在activity的onCreate里面构造出来
* 在activity的生命周期中调用此类相对应的生命周期方法
*
* @param activity 扫描的activity
* @param scanPreview 预览的SurfaceView
* @param scanContainer 扫描的布局,全屏布局
* @param scanCropView 扫描的矩形区域
* @param scanLine 扫描线
*/
public ScanManager(Activity activity, SurfaceView scanPreview, View scanContainer,
View scanCropView, ImageView scanLine, int scanMode, ScanListener listener) {
this.activity = activity;
this.scanPreview = scanPreview;
this.scanContainer = scanContainer;
this.scanCropView = scanCropView;
this.scanLine = scanLine;
this.listener = listener;
this.scanMode = scanMode;
//启动动画
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);
}
示例2: translateHeader
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 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);
}
}
示例3: ScanManager
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 用于启动照相机扫描二维码,在activity的onCreate里面构造出来
* 在activity的生命周期中调用此类相对应的生命周期方法
* @param activity 扫描的activity
* @param scanPreview 预览的SurfaceView
* @param scanContainer 扫描的布局,全屏布局
* @param scanCropView 扫描的矩形区域
* @param scanLine 扫描线
*
*
*/
public ScanManager(Activity activity, SurfaceView scanPreview, View scanContainer,
View scanCropView, ImageView scanLine, int scanMode, ScanListener listener) {
this.activity=activity;
this.scanPreview=scanPreview;
this.scanContainer=scanContainer;
this.scanCropView=scanCropView;
this.scanLine=scanLine;
this.listener=listener;
this.scanMode=scanMode;
//启动动画
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);
}
示例4: createOptionDisappearAnimation
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
@Override
public Animation createOptionDisappearAnimation(OptionButton optionButton, int index) {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateAnimation= new TranslateAnimation(
0
,getYMenuButton().getX() - optionButton.getX()
,0
,getYMenuButton().getY() - optionButton.getY()
);
translateAnimation.setDuration(getOptionSD_AnimationDuration());
AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
alphaAnimation.setDuration(getOptionSD_AnimationDuration());
animationSet.addAnimation(translateAnimation);
animationSet.addAnimation(alphaAnimation);
//为不同的Option设置延时
if (index % 2 == 0) {
animationSet.setStartOffset(getOptionSD_AnimationDuration()/2);
}
return animationSet;
}
示例5: showTipViewAndDelayClose
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
public void showTipViewAndDelayClose(String tip) {
tipView.setText(tip);
Animation mShowAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
mShowAction.setDuration(500);
tipView.startAnimation(mShowAction);
tipView.setVisibility(View.VISIBLE);
tipView.postDelayed(new Runnable() {
@Override
public void run() {
Animation mHiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
-1.0f);
mHiddenAction.setDuration(500);
tipView.startAnimation(mHiddenAction);
tipView.setVisibility(View.GONE);
}
}, 2200);
}
示例6: initAnimation
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
private void initAnimation() {
paint.setStrokeWidth(getHeight() * 0.01f);
paint.setAntiAlias(true);
paint.setDither(true);
paint.setColor(Color.argb(248, 255, 255, 255));
paint.setStrokeWidth(20f);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paintGlow.set(paint);
paintGlow.setColor(Color.argb(235, 74, 138, 255));
paintGlow.setStrokeWidth(30f);
paintGlow.setMaskFilter(new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL));
float deltaY = (CameraOverlayView.PADDING * 2) * getHeight();
Log.i(TAG, String.format("Delta Y : %s", deltaY));
TranslateAnimation mAnimation = new TranslateAnimation(0f, 0f, 0f, deltaY);
mAnimation.setDuration(3000);
mAnimation.setRepeatCount(-1);
mAnimation.setRepeatMode(Animation.REVERSE);
mAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
setAnimation(mAnimation);
}
示例7: translateAlphaFinishAnimation
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 结束时的动画 平移到底部
*/
public static Animation translateAlphaFinishAnimation() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
setDefaultConfig(translateAnimation, true);
setDefaultConfig(alphaAnimation, true);
translateAnimation.setDuration(DEFAULT_DIALOG_FINISH_ANIM_TIME);
alphaAnimation.setDuration(DEFAULT_DIALOG_FINISH_ANIM_TIME);
AnimationSet animationSet = new AnimationSet(false);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
return animationSet;
}
示例8: onCreate
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_scan);
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);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
示例9: startAnim
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
private void startAnim(View widget) {
int distance = widget.getHeight();
widget.setVisibility(0);
this.mFloatLayout.setVisibility(0);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
alphaAnimation.setDuration(200);
alphaAnimation.setStartOffset(200);
this.mFloatLayout.setAnimation(alphaAnimation);
this.mAnimation = new TranslateAnimation(0.0f, 0.0f, (float) distance, 0.0f);
this.mAnimation.setDuration(200);
this.mAnimation.setStartOffset(200);
widget.setAnimation(this.mAnimation);
this.mAnimation.start();
alphaAnimation.start();
}
示例10: loadLayoutAnimation
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 对话框的布局动画
*/
@Override
public Animation loadLayoutAnimation() {
if (layoutAnim) {
if (layoutAnimation == null) {
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 0f,
Animation.RELATIVE_TO_PARENT, 1f, Animation.RELATIVE_TO_PARENT, 0f);
setDefaultConfig(translateAnimation, false);
translateAnimation.setDuration(160);
return translateAnimation;
} else {
return layoutAnimation;
}
}
return null;
}
示例11: display
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
public void display(float x) {
this.startPositionX = x;
this.lastPositionX = x;
recordButtonFab.setVisibility(View.VISIBLE);
float translation = ViewCompat.getLayoutDirection(recordButtonFab) ==
ViewCompat.LAYOUT_DIRECTION_LTR ? -.25f : .25f;
AnimationSet animation = new AnimationSet(true);
animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, translation,
Animation.RELATIVE_TO_SELF, translation,
Animation.RELATIVE_TO_SELF, -.25f,
Animation.RELATIVE_TO_SELF, -.25f));
animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f,
Animation.RELATIVE_TO_SELF, .5f,
Animation.RELATIVE_TO_SELF, .5f));
animation.setFillBefore(true);
animation.setFillAfter(true);
animation.setDuration(ANIMATION_DURATION);
animation.setInterpolator(new OvershootInterpolator());
recordButtonFab.startAnimation(animation);
}
示例12: moveTo
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
public void moveTo(float x) {
this.lastPositionX = x;
float offset = getOffset(x);
int widthAdjustment = getWidthAdjustment();
Animation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, widthAdjustment + offset,
Animation.ABSOLUTE, widthAdjustment + offset,
Animation.RELATIVE_TO_SELF, -.25f,
Animation.RELATIVE_TO_SELF, -.25f);
translateAnimation.setDuration(0);
translateAnimation.setFillAfter(true);
translateAnimation.setFillBefore(true);
recordButtonFab.startAnimation(translateAnimation);
}
示例13: onCreate
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
@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);
}
示例14: adjustSizes
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
private void adjustSizes(boolean isAnimated) {
int width = getWidth();
if (width > 0 && this.items != null) {
LayoutParams viewLayoutParams = (LayoutParams) this.currentView.getLayoutParams();
viewLayoutParams.width = width / this.items.length;
this.currentView.setLayoutParams(viewLayoutParams);
if (!this.inAnimation) {
if (isAnimated) {
this.inAnimation = true;
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, this.currentIndex - this.lastIndex, 0, 0, 0, 0);
animation.setDuration(300);
animation.setAnimationListener(this);
this.currentView.startAnimation(animation);
return;
}
viewLayoutParams.leftMargin = this.currentIndex * viewLayoutParams.width;
this.currentView.setLayoutParams(viewLayoutParams);
}
}
}
示例15: boundBack
import android.view.animation.TranslateAnimation; //导入依赖的package包/类
/**
* 将内容布局移动到原位置 可以在UP事件中调用, 也可以在其他需要的地方调用, 如手指移动到当前ScrollView外时
*/
private void boundBack() {
if (!isMoved) {
return; // 如果没有移动布局, 则跳过执行
}
// 开启动画
TranslateAnimation anim = new TranslateAnimation(0, 0, contentView.getTop(), originalRect.top);
anim.setDuration(ANIM_TIME);
contentView.startAnimation(anim);
// 设置回到正常的布局位置
contentView.layout(originalRect.left, originalRect.top, originalRect.right,
originalRect.bottom);
// 将标志位设回false
canPullDown = false;
canPullUp = false;
isMoved = false;
}