i create animation, at the start of animation i am changing the styles of some button and then and at the end of the animation i am changing buttons style back to its previous style but that's is not happing it still show the same style that was set at onAnimationStart()
Every thing looks fine the control is also going through the loop in onActionEnd() but still no update in buttons style. Help Please
public void WrongAnim()
{
AlphaAnimation animation = new AlphaAnimation(1, 0.5f);
//animation.setRepeatCount(1);
animation.setDuration(2000);
animation.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
Log.v("Wronganim", "end...");
for(int i=0; i<input_boxes.size(); i++)
{
input_boxes.get(i).getBox().setTextAppearance(context, R.style.textstyle);
}
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
Log.v("Wronganim", "start......");
for(int i=0; i<input_boxes.size(); i++)
{
input_boxes.get(i).getBox().setTextAppearance(context, R.style.redtext);
}
}
});
inputbar.startAnimation(animation); //lienar layout inflate from xml
}
Related
i am applying animation in android listview. But it is working only the first row of the listview. it doesn't work on the whole listview. Can anyone please help me?
MY Code is Below
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_top);
animation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
upcoming_list.setPressed(true);
upcoming_list.startAnimation(animation);
}
});
upcoming_list.clearAnimation();
upcoming_list.startAnimation(animation);
And My Animation XML
<translate
android:duration="1500"
android:fromYDelta="-100%p"
android:toYDelta="1" />
I simply want to use this working animation code I have in a more efficient manner. The code below works exactly as I want it to but I don't want to copy and paste this everywhere in the thirty places across several activities in which I'll be using this specific fadeout animation. How can I set up a class to do this? The primary problem is setting the view to invisible in onAnimationEnd.
final TextView ph = (TextView) findViewById(R.id.textPlaceholder);
final Animation fadeOut = new AlphaAnimation(1.0f, 0.0f);
fadeOut.setStartOffset(1000);
fadeOut.setDuration(500);
fadeOut.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
ph.setVisibility(View.INVISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
});
ph.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ph.startAnimation(fadeOut);
}
});
Create a helper class:
Class ClickToFadeOutAnimation
private View view;
public static void attachTo(View view) {
new FadeOutAnimation(View view);
}
public FadeOutAnimation(View view) {
this.view = view;
view.setOnCLickListsner(new OnClickListener() {
animate();
)
}
public void animate() {
Animation fadeOut = ...
.. rest of your animation code
}
}
And to use it:
TextView ph = (TextView) findViewById(R.id.textPlaceholder);
ClickToFadeOutAnimation.attachTo(ph);
Extend the AlphaAnimation class where you set the duration, offset and AnimationListener in the constructor.
I want to enable animations in my app dynamically as we do manually from Settings>Display>Animation>All Animation.
I have tried appended code but to no avail,
Settings.System.putInt(getContentResolver(), Settings.System.WINDOW_ANIMATION_SCALE, 1);
Settings.System.putInt(getContentResolver(), Settings.System.TRANSITION_ANIMATION_SCALE, 1);
Please help
Imran
i think., you can do it for your app., but if you are taking it for your device means you can read the flags., if it is disabled you can intent the setting panel to open to enable it by the user.
source:
animation enable
// declare animation
Animation animationSlideInLeft, animationSlideOutRight;
// Now we are giveing image view animated
image1 = (ImageView)findViewById(R.id.image1);
image2 = (ImageView)findViewById(R.id.image2);
image3 = (ImageView)findViewById(R.id.image3);
animationSlideInLeft = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
animationSlideOutRight = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
animationSlideInLeft.setDuration(1000);
animationSlideOutRight.setDuration(1000);
animationSlideInLeft.setAnimationListener(animationSlideInLeftListener);
animationSlideOutRight.setAnimationListener(animationSlideOutRightListener);
curSlidingImage = image1;
image1.startAnimation(animationSlideInLeft);
image1.setVisibility(View.VISIBLE);
// Create animation listener
AnimationListener animationSlideInLeftListener
= new AnimationListener(){
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
if(curSlidingImage == image1){
image1.startAnimation(animationSlideOutRight);
}else if(curSlidingImage == image2){
image2.startAnimation(animationSlideOutRight);
}else if(curSlidingImage == image3){
image3.startAnimation(animationSlideOutRight);
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}};
// and paus clear the listener
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
image1.clearAnimation();
image2.clearAnimation();
image3.clearAnimation();
}
Reference from here
2.Same this one you can do with add xml into res/anim/ folder
A view after an scale animation, have not resize to new position.
I using a android animation (ScaleAnimation) to make a layout(screen size when start) scale to 0.95 times size by itself and the scale reference the screen central point.
final AnimationListener al2 = new AnimationListener() {
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation arg0) {
}
};
public void animScale(){
ScaleAnimation sa = new ScaleAnimation(1,0.95f,1,0.95f, topLayout.getMeasuredWidth()/2, topLayout.getMeasuredHeight()/2);
sa.setDuration(500);
sa.setFillEnabled(true);
sa.setFillAfter(true);
sa.setAnimationListener(al2);
topLayout.startAnimation(sa);
}
public void onCreate(Bundle savedInstanceState) {
scaleButton = (Button) findViewById(R.id.scaleButton);
scaleButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
animScale();
}
});
}
after this animation my layout have been changed to new position, but when i click again the button
the layout always from screen size scale to 0.95 times.
that show me the layout never change the actual size through the animation.
what code i need to add in the animation listener animation end?
i hope to achieve when i click the button it will do that,
screen size -> screen size *0.95 -> screen size *0.95^2 ->........
thanks a lot.
The problem occurs because you are using Animation class. With Animation you only change the visible appearance.
In your case you need to use Animator which also updates positions and dimensions.
The difference between Animation and Animator is explained in this question.
ScaleAnimation doesn't changes layout's parameters. It animates without changing parameters for a smoother animation.
You can create a Boolean instance variable
Boolean animationDone = false;
and set it to true in onAnimationEnd to indicate if the animation is done
public void onAnimationEnd(Animation arg0) {
animationDone=true;
}
and check it in animScale before animating to prevent multiple animations....
public void animScale(){
if ( animationDone ) return;
//..... animation code here...
}
My problem is:
I customized a view as below JPTabBarMainMenu, set it as part of a listview header. in JPTabBarMainMenu there are two buttons, animation will runs when I click one of the two buttons.
the problem is the animation runs very well on android 2.3.3, but won't run on 4.0.3 and 4.0.4, I guess it won't work on 4.x. I don't know the reason.
JPTabBarMainMenu extends FrameLayout{
code as below:
onAnimationStart/onAnimationRepeat/onAnimationEnd won't getting called.
FrameLayout.LayoutParams params = (LayoutParams) mSlider.getLayoutParams();
JPTranslateAnimation slideRightAnimation = new MaringTranslateTranslateAnimation(params.leftMargin, tabItem.getLeft() + offset / 2, 0, 0, mSlider);
slideRightAnimation.setDuration(slideRightAnimation.computeDuration(
JPTranslateAnimation.ANIMATION_STD_DURATION, mTabLayout.getWidth()));
slideRightAnimation.setRepeatCount(0);
slideRightAnimation.setFillAfter(true);
slideRightAnimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
isRunningAnimation = true;
if(mSelectionChangedListener != null){
mSelectionChangedListener.onSelectionChangedStart(oldIndex, mCurrentTab);
}
if(oldIndex != -1){
TabItem item = mTabItems.get(oldIndex);
item.onTabItemSelected(false);
}
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
isRunningAnimation = false;
if(mSelectionChangedListener != null){
mSelectionChangedListener.onSelectioinChangedEnd(oldIndex, mCurrentTab);
}
TabItem item = mTabItems.get(mCurrentTab);
item.onTabItemSelected(true);
if(mDrawSelectorByDefault == false){
mSlider.setVisibility(View.INVISIBLE);
}
}
});
if(mSlider.getVisibility() != View.VISIBLE){
mSlider.setVisibility(View.VISIBLE);
}
mSlider.startAnimation(slideRightAnimation);