The following code examples are extracted from open source projects.
Code Example 1:
Source
AnimationHelper.java
public static Animation inFromRightAnimation() {
Animation inFromRight =
new TranslateAnimation(
Animation.RELATIVE_TO_PARENT
, +1.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f);
inFromRight.setDuration(350);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
Code Example 2:
Source
LayoutAnimation2.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, mStrings));
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);
animation = 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
);
animation.setDuration(100);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
ListView listView = getListView();
listView.setLayoutAnimation(controller);
}
Code Example 3:
Source
UIFactory.java
@Override
public void run() {
Animation a = null;
if (this.recording == false) {
a = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -1,
Animation.RELATIVE_TO_SELF, 0);
} else {
a = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, -1);
}
a.setDuration(250);
a.setInterpolator(AnimationUtils.loadInterpolator(this.activity,
android.R.anim.anticipate_overshoot_interpolator));
View stopRecView = activity.findViewById(R.id.TapToStopRecordingTextView);
stopRecView.startAnimation(a);
}
Code Example 4:
Source
SlidingPanel.java
public void toggle() {
TranslateAnimation anim=null;
isOpen=!isOpen;
if (isOpen) {
setVisibility(View.VISIBLE);
anim=new TranslateAnimation(0.0f, 0.0f,
getHeight(),
0.0f);
}
else {
anim=new TranslateAnimation(0.0f, 0.0f, 0.0f,
getHeight());
anim.setAnimationListener(collapseListener);
}
anim.setDuration(speed);
anim.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(anim);
}
Code Example 5:
Source
SlidingPanel.java
public void toggle() {
TranslateAnimation anim=null;
AnimationSet set=new AnimationSet(true);
isOpen=!isOpen;
if (isOpen) {
setVisibility(View.VISIBLE);
anim=new TranslateAnimation(0.0f, 0.0f,
getHeight(),
0.0f);
}
else {
anim=new TranslateAnimation(0.0f, 0.0f, 0.0f,
getHeight());
anim.setAnimationListener(collapseListener);
set.addAnimation(fadeOut);
}
set.addAnimation(anim);
set.setDuration(speed);
set.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(set);
}
Code Example 6:
Source
Util.java
public static Animation slideOut(View view, int to) {
view.setVisibility(View.INVISIBLE);
Animation anim;
switch (to) {
case DIRECTION_LEFT:
anim = new TranslateAnimation(0, -view.getWidth(), 0, 0);
break;
case DIRECTION_RIGHT:
anim = new TranslateAnimation(0, view.getWidth(), 0, 0);
break;
case DIRECTION_UP:
anim = new TranslateAnimation(0, 0, 0, -view.getHeight());
break;
case DIRECTION_DOWN:
anim = new TranslateAnimation(0, 0, 0, view.getHeight());
break;
default:
throw new IllegalArgumentException(Integer.toString(to));
}
anim.setDuration(500);
view.startAnimation(anim);
return anim;
}
Code Example 7:
Source
Util.java
public static Animation slideIn(View view, int from) {
view.setVisibility(View.VISIBLE);
Animation anim;
switch (from) {
case DIRECTION_LEFT:
anim = new TranslateAnimation(-view.getWidth(), 0, 0, 0);
break;
case DIRECTION_RIGHT:
anim = new TranslateAnimation(view.getWidth(), 0, 0, 0);
break;
case DIRECTION_UP:
anim = new TranslateAnimation(0, 0, -view.getHeight(), 0);
break;
case DIRECTION_DOWN:
anim = new TranslateAnimation(0, 0, view.getHeight(), 0);
break;
default:
throw new IllegalArgumentException(Integer.toString(from));
}
anim.setDuration(500);
view.startAnimation(anim);
return anim;
}
Code Example 8:
Source
MainMenu.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
analyticsTracker();
setContentView(R.layout.main);
prepareMenu();
String[] keys = actions.keySet().toArray(new String[actions.keySet().size()]);
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, keys));
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);
animation = 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
);
animation.setDuration(100);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
ListView listView = getListView();
listView.setLayoutAnimation(controller);
}
Code Example 9:
Source
LiqoidMainActivity.java
public Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(ANIMATION_DURATION);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
Code Example 10:
Source
LiqoidMainActivity.java
public Animation inFromLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(ANIMATION_DURATION);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
Code Example 11:
Source
LiqoidMainActivity.java
public Animation outToRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(ANIMATION_DURATION);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
Code Example 12:
Source
LiqoidMainActivity.java
public Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(ANIMATION_DURATION);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
Code Example 13:
Source
PassView.java
private Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(ANIMATION_DURATION);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
Code Example 14:
Source
PassView.java
private Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(ANIMATION_DURATION);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
Code Example 15:
Source
PassView.java
private Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(ANIMATION_DURATION);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
Code Example 16:
Source
PassView.java
private Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(ANIMATION_DURATION);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
Code Example 17:
Source
PassView.java
private Animation inFromBottomAnimation() {
Animation inFromBottom = 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);
inFromBottom.setDuration(ANIMATION_DURATION);
inFromBottom.setInterpolator(new AccelerateInterpolator());
return inFromBottom;
}
Code Example 18:
Source
PassView.java
private Animation outToTopAnimation() {
Animation outtoTop = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f);
outtoTop.setDuration(ANIMATION_DURATION);
outtoTop.setInterpolator(new AccelerateInterpolator());
return outtoTop;
}
Code Example 19:
Source
PassView.java
private Animation inFromTopAnimation() {
Animation inFromTop = 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);
inFromTop.setDuration(ANIMATION_DURATION);
inFromTop.setInterpolator(new AccelerateInterpolator());
return inFromTop;
}
Code Example 20:
Source
PassView.java
private Animation outToBottomAnimation() {
Animation outToBottom = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f);
outToBottom.setDuration(ANIMATION_DURATION);
outToBottom.setInterpolator(new AccelerateInterpolator());
return outToBottom;
}
Code Example 21:
Source
GalleryEx.java
private Animation genAnimation() {
TranslateAnimation translate = new TranslateAnimation(mTouchEndX,
mTouchEndX, 0, 0);
translate.setDuration(25);
translate.setFillAfter(true);
return translate;
}
Code Example 22:
Source
DeleteZone.java
private void createAnimations() {
if (mInAnimation == null) {
mInAnimation = new FastAnimationSet();
final AnimationSet animationSet = mInAnimation;
animationSet.setInterpolator(new AccelerateInterpolator());
animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f));
if (mPosition == POSITION_TOP) {
animationSet.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f));
} else {
animationSet.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,
Animation.RELATIVE_TO_SELF, 0.0f));
}
animationSet.setDuration(ANIMATION_DURATION);
}
if (mOutAnimation == null) {
mOutAnimation = new FastAnimationSet();
final AnimationSet animationSet = mOutAnimation;
animationSet.setInterpolator(new AccelerateInterpolator());
animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f));
if (mPosition == POSITION_TOP) {
animationSet.addAnimation(new FastTranslateAnimation(Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f));
} else {
animationSet.addAnimation(new FastTranslateAnimation(Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 1.0f));
}
animationSet.setDuration(ANIMATION_DURATION);
}
}
Code Example 22:
Source
DockBar.java
public void open(){
dispatchDockBarEvent(true);
setClickable(false);
mState=OPEN;
setVisibility(View.VISIBLE);
int x=0;
int y=0;
switch (mPosition) {
case LEFT:
x=getWidth();
break;
case RIGHT:
x=getWidth();
break;
case TOP:
y=-getHeight();
break;
case BOTTOM:
y=getHeight();
break;
}
TranslateAnimation anim=new TranslateAnimation(x, 0,y, 0);
anim.setDuration(ANIM_DURATION);
startAnimation(anim);
}
Code Example 23:
Source
AnimationLayout.java
public void open(){
dispatchDockBarEvent(true);
setClickable(false);
mState=OPEN;
setVisibility(View.VISIBLE);
int x=0;
int y=0;
switch (mPosition) {
case LEFT:
x=getWidth();
break;
case RIGHT:
x=getWidth();
break;
case TOP:
y=-getHeight();
break;
case BOTTOM:
y=getHeight();
break;
}
TranslateAnimation anim=new TranslateAnimation(x, 0,y, 0);
anim.setDuration(ANIM_DURATION);
startAnimation(anim);
}
Code Example 24:
Source
AnimationLayout.java
public void toggleSidebar() {
if (mContent.getAnimation() != null) {
return;
}
if (mOpened) {
/* opened, make close animation*/
mAnimation = new TranslateAnimation(0, -mSidebarWidth, 0, 0);
mAnimation.setAnimationListener(mCloseListener);
} else {
/* not opened, make open animation */
mAnimation = new TranslateAnimation(0, mSidebarWidth, 0, 0);
mAnimation.setAnimationListener(mOpenListener);
}
mAnimation.setDuration(DURATION);
mAnimation.setFillAfter(true);
mAnimation.setFillEnabled(true);
mContent.startAnimation(mAnimation);
}
Code Example 25:
Source
TagButton.java
public Animation createTranslateAnimation(long durationMillis) {
if (old_x == getLeft() && old_y == getTop()) {
return null;
}
int dx = getLeft() - old_x;
int dy = getTop() - old_y;
Animation a = new TranslateAnimation(-dx, 0, -dy, 0);
a.setFillAfter(true);
a.setDuration(durationMillis);
old_x = getLeft();
old_y = getTop();
return a;
}
Code Example 26:
Source
TagButton.java
public Animation createTranslateAnimation(long durationMillis) {
if (old_x == getLeft() && old_y == getTop()) {
return null;
}
int dx = getLeft() - old_x;
int dy = getTop() - old_y;
Animation a = new TranslateAnimation(-dx, 0, -dy, 0);
a.setFillAfter(true);
a.setDuration(durationMillis);
old_x = getLeft();
old_y = getTop();
return a;
}
Code Example 27:
Source
AnimateDrawables.java
public SampleView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
Drawable dr = context.getResources().getDrawable(R.drawable.beach);
dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
Animation an = new TranslateAnimation(0, 100, 0, 200);
an.setDuration(2000);
an.setRepeatCount(-1);
an.initialize(10, 10, 10, 10);
mDrawable = new AnimateDrawable(dr, an);
an.startNow();
}
Code Example 28:
Source
LayoutAnimation2.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter(this,
android.R.layout.simple_list_item_1, mStrings));
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);
animation = 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
);
animation.setDuration(100);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
ListView listView = getListView();
listView.setLayoutAnimation(controller);
}
Code Example 29:
Source
AnimationHelper.java
public static Animation outToLeftAnimation() {
Animation outtoLeft =
new TranslateAnimation(
Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, -1.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f);
outtoLeft.setDuration(350);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
Code Example 30:
Source
AnimationHelper.java
public static Animation inFromLeftAnimation() {
Animation inFromLeft =
new TranslateAnimation(
Animation.RELATIVE_TO_PARENT
, -1.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f);
inFromLeft.setDuration(350);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
Code Example 31:
Source
AnimationHelper.java
public static Animation outToRightAnimation() {
Animation outtoRight =
new TranslateAnimation(
Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, +1.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f
, Animation.RELATIVE_TO_PARENT
, 0.0f );
outtoRight.setDuration(350);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
thank you :)
ReplyDelete