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" />
Related
I have Button which function is to animate one of my ImageView for a second and delete specific table, recreate and insert the default value. Everything's working fine but one of my requirements is to show the animation aleast 1 second even recreating table is done. how can i achieve this?
NOTE: I animate my ImageView with Rotate effect so it will looks like refreshing.
refreshDatabase function
public void refreshDatabase(View v){
Button btnRefresh = (Button)findViewById(R.id.btnRef);
ImageView refreshing = (ImageView) findViewById(R.id.rfs);
btnRefresh.setClickable(false);
btnRefresh.setEnabled(false);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//I want to start animation here
refreshing.startAnimation(animation);
....recreat table here
//Stop animation after 1 second
refreshing.clearAnimation();
}
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="300"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
I try to add this,
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//recreate table here
refreshing.clearAnimation();
}
}, 1000);
but i got an error Handler is abstract; cannot be instantiated.
Anybody can help me? Thank You!!!
You can use Handler which will wait for a second and then execute clearAnimation method:
public void refreshDatabase(View v){
Button btnRefresh = (Button)findViewById(R.id.btnRef);
ImageView refreshing = (ImageView) findViewById(R.id.rfs);
btnRefresh.setClickable(false);
btnRefresh.setEnabled(false);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//I want to start animation here
refreshing.startAnimation(animation);
....recreat table here
//Stop animation after 1 second
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
refreshing.clearAnimation();
}
}, 1000);
}
Use a Handler (http://developer.android.com/reference/android/os/Handler.html) to post delay a message or a Runnable in which you call clearAnimation()
You can set the duration of the animation like the following example in your rotate.xml file
<rotate android:interpolator="#android:anim/accelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000" //set this property (1000 is 1second)
android:startOffset="1500"/>
Or you can do it programatically too by using setDuration() .
ImageView iv_follow_insta = findViewById(R.id.iv_follow_insta);
Animation zoomInanimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.dialog_zoomin);
Animation zoomOutanimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.dialog_zoomout);
zoomOutanimation.setAnimationListener(new Animation.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) {
iv_follow_insta.startAnimation(zoomInanimation);
}
});
zoomInanimation.setAnimationListener(new Animation.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) {
iv_follow_insta.startAnimation(zoomOutanimation);
}
});
iv_follow_insta.startAnimation(zoomInanimation);
iv_follow_insta.startAnimation(zoomOutanimation);
new Handler().postDelayed(() -> {
zoomInanimation.setAnimationListener(null);
zoomOutanimation.setAnimationListener(null);
iv_follow_insta.clearAnimation();
}, 10000);
try this
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
}
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
I want to make a layout animated through translation animation from screen's particular X Y position. and this is happening very correcty. now the problem starts when animations completes the layout again go to screen's top rihgt corner. i want the layout stay at the same position on which the animation ends.
AnimationListener animationListener = new AnimationListener() {
#Override
public void onAnimationEnd(Animation arg0) {
drawer_layout.setVisibility(View.VISIBLE);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
drawer_layout.setVisibility(View.VISIBLE);
}
};
final Animation animTranslate = AnimationUtils.loadAnimation(this,
R.anim.top_to_bottom_in);
animTranslate.setAnimationListener(animationListener);
drawer_layout = (LinearLayout) findViewById(R.id.drawer_layout);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// bitmapBackground = CaptureBackground();
faded_layout.setBackgroundColor(Color.parseColor("#50ffffff"));
// HandleDropAnimation(drawer_layout);
drawer_layout.startAnimation(animTranslate);
}
});
and this is my xml.
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromYDelta="25%p"
android:toYDelta="50%p" />
Call
animTranslate.setFillAfter(true);
before you start the animation. According to java docs:
If fillAfter is true, the transformation that this animation performed will persist when it is finished.
use before animation starts
animTranslate.setFillAfter(true);
I am animating an ImageView so that when you click the image the animation occurs (then later it resets) but my problem is that if you click again where the image sat originally - the animation starts from the beginning right away with out finishing (it just resets and starts again.
so I tried using
setEnabled(false)
which works great, the animation continues on its path up perturbed by any random clicking, now the only problem is getting the ImageView enabled again - at about the same time as the animation stops
here's what i have
stopImage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mpButtonClick.start();
stopImage.setEnabled(false);
TranslateAnimation anim = new TranslateAnimation(0f,250 + Math.round(Math.random() * (-700)),0f,-300f);
anim.setDuration(4200);
anim.setRepeatCount(0);
stopImage.startAnimation(anim);
now is there an easy way i can call setEnabled(true) after a some time has passed?
You could try using an AnimationListener and then calling setEnabled(true) from onAnimationEnd().
Something like this:
stopImage.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
mpButtonClick.start();
TranslateAnimation anim = new TranslateAnimation(0f,250 + Math.round(Math.random() * (-700)),0f,-300f);
anim.setDuration(4200);
anim.setRepeatCount(0);
anim.setAnimationListener(new Animation.AnimationListener()
{
#Override
public void onAnimationStart(Animation animation)
{
stopImage.setEnabled(false);
}
#Override
public void onAnimationRepeat(Animation animation)
{
}
#Override
public void onAnimationEnd(Animation animation)
{
stopImage.setEnabled(true);
}
});
stopImage.startAnimation(anim);
}
}
Here's the documentation for AnimationListeners.