I have some troubles with Interpolator...
I tried to make fadeIN/OUT but this function does not work. I have set delay 1000ms, but fading effect is not shown. Could you help me out? I checked some tutorials and all should be set correctly except layout width/height which should not be presented in XML. When i remove them there is message that those fields are mandatory:(
XMLs:
FADEIN
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
---------------------
FADEOUT
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:interpolator="#android:anim/decelerate_interpolator"
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0">
</alpha>
---------
Main Activity
public class WelcomePage extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome_page);
new Handler().postDelayed(new Thread(){
public void run(){
Intent mainMenu = new Intent(WelcomePage.this,mainMenu.class);
WelcomePage.this.startActivity(mainMenu);
WelcomePage.this.finish();
overridePendingTransition(R.layout.fadein,R.layout.fadeout);
}
},GCEngine.GAME_THREAD_DELAY);
}
}
Set this to fade_out:
android:fillAfter="true"
Than use this code:
new Handler().postDelayed(new Thread(){
public void run(){
Intent mainMenu = new Intent(WelcomePage.this,mainMenu.class);
WelcomePage.this.startActivity(mainMenu);
overridePendingTransition(R.layout.fadein,R.layout.fadeout);
WelcomePage.this.finish();
}
},GCEngine.GAME_THREAD_DELAY);
Related
one more problem.
I am trying to make RecycleView items fade away, so I wrote an XML animation for each item, then a layer animation XML and added code in Java main activity. Everything works ok, views disappear, but the problem is, after they all disappear, they all of a sudden appear back again on their own! What can be the reason? How to keep alpha 0?
Codes:
Main activity method:
private void layoutDisappear(final RecyclerView recyclerView) {
if(recyclerView.isAnimating()){
return;
}
final Context context = recyclerView.getContext();
final LayoutAnimationController controller =
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_recycleview_disappear);
recyclerView.setLayoutAnimation(controller);
recyclerView.setLayoutAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationEnd(Animation animation) {
}
});
recyclerView.scheduleLayoutAnimation();
Item animation XML:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1400">
<alpha
android:fromAlpha="1"
android:interpolator="#android:anim/decelerate_interpolator"
android:toAlpha="0" />
<scale
android:fromXScale="100%"
android:fromYScale="100%"
android:interpolator="#android:anim/decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="102%"
android:toYScale="102%" />
</set>
Layer XML:
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="#anim/item_recycleview_disappear"
android:animationOrder="reverse"
android:delay="7%" />
You need add android:fillAfter="true" property to Item animation XML to keep animation changes.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:duration="1400">
...
</set>
I have an app and I want to open an activity using this transition
(Google Maps does this too if you open the settings).
How can I achieve this?
write your code in oncreate method of next activity
Create XML file for fade-in animation, /res/anim/fadein.xml.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="2000"
/>
</set>
Create XML file for fade-out animation, /res/anim/fadeout.xml.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="2000"
/>
</set>
In your Activity
final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
buttonToNextActivity.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
image.startAnimation(animationFadeIn);
}});
Same as it is find write in the SecondActivity and call the animation onBackPressed(){...}
Try adding the following line after starting the activity:
overridePendingTransition(R.anim.youranimation, R.anim.default_anim);
For example:
Intent intent = new Intent (context, YourActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.youranimation, R.anim.default_anim);
default_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_shortAnimTime"
android:fromYDelta="0%p"
android:toYDelta="0%p" />
Change values.
I used this animation blink.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:duration="1000"
android:repeatCount="infinite"
android:interpolator="#android:anim/accelerate_interpolator"
/>
</set>
I called it like this to stop it after 5 seconds:
mainThreadhanlder.post(new Runnable() {
#Override
public void run() {
view.startAnimation(blinkAnim);
}
});
mainThreadhanlder.postDelayed(new Runnable() {
#Override
public void run() {
view.clearAnimation();
}
}, 5000);
but the problem is the animation is not working on the downside of the textView: The downside of the 00 can be shown that the animation is not working proporely !
so, what can be the source of the problem ?
Just add Padding In your TextView
<TextView
...
android:padding="5dp"/>
I'm having a TextView which is animated to slide out on click. Now when I again click the area where TextView was layout the click event is still getting fired as if TextView is still there. I want the TextView to behave as if it's not there once hidden through animation.
Following are my animation files.
res/anim/slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="#android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
res/anim/slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:interpolator="#android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Following is my layout xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="#+id/anim_tv"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/hello_world"
android:gravity="center"
android:background="#8800ff00"/>
</RelativeLayout>
And following is Activity code.
public class MainActivity extends Activity {
TextView animTV;
Animation animSlideIn;
Animation animSlideOut;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
animTV = (TextView) findViewById(R.id.anim_tv);
animTV.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
hide();
}
});
// load the animation
animSlideIn = AnimationUtils.loadAnimation(this, R.anim.slide_in);
animSlideOut = AnimationUtils.loadAnimation(this, R.anim.slide_out);
show();
}
private void show() {
animTV.startAnimation(animSlideIn);
}
private void hide() {
animTV.startAnimation(animSlideOut);
}
}
Can anybody suggest a solution to this issue?
Thanks,
Ammar
you can implements Animation.AnimationListener, and when onAnimationEnd is called you can change the TextView's visibility to gone
According to #blackbelt suggestion I did following update in Activity.
animSlideOut.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) { }
#Override
public void onAnimationEnd(Animation animation) {
animTV.setVisibility( View.GONE );
}
#Override
public void onAnimationRepeat(Animation animation) { }
});
#blackbelt solution was partially helpful. To make it fully working I had to updated the slide_out.xml to set the android:fillAfter attribute to false.
I'm trying to make a animation from the top to the button.
If I click on a button, he should show a View from top. And if I'm clicking again, he should animate it back to the top. This is, what i have:
MainActivity:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btFilterDown = (Button) findViewById(R.id.btFilterDown);
Button btFilterUp = (Button) findViewById(R.id.btFilterUp);
final View layout = findViewById(R.id.slide);
layout.setVisibility(View.GONE);
btFilterUp.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
hideView(layout);
}
});
btFilterDown.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showView(layout);
}
});
}
private void hideView(final View view){
Animation animation = AnimationUtils.loadAnimation(this, R.layout.slide_out_up);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {}
#Override
public void onAnimationRepeat(Animation animation) {}
#Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.GONE);
}
});
view.startAnimation(animation);
}
private void showView(final View view){
Animation animation = AnimationUtils.loadAnimation(this, R.layout.slide_in_down);
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {}
#Override
public void onAnimationRepeat(Animation animation) {}
#Override
public void onAnimationEnd(Animation animation) {
view.setVisibility(View.VISIBLE);
}
});
view.startAnimation(animation);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Slide_in_down.xml:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:fromYDelta="-1000"
android:duration="#android:integer/config_longAnimTime" />
Slide_out_up.xml:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:toXDelta="0"
android:toYDelta="-1000"
android:duration="#android:integer/config_longAnimTime" />
And my main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#android:color/darker_gray" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white" >
<Button
android:id="#+id/btFilterDown"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="FILTER!!!"/>
</LinearLayout>
<LinearLayout
android:id="#+id/slide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#99009900"
android:orientation="vertical">
<Button
android:id="#+id/btFilterUp"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text=" NO FILTER!!!"/>
</LinearLayout>
</LinearLayout>
So now I have 2 problems:
First:
The button of my first layout is not visible anymore, if the second layout is over it. I want to make the view, which animated in, transparency. But it looks very bad, if the objects from the first view away.
How can I lay the animated layout over the first, so that all objects on the first layout are visible?
Second:
The animation should start at the bottom of the Actionbar. I mean, if the layout is coming in, that he starts on bottom edge and not on the top of the screen.
How can I set the start point of the animation?
Thanks a lot :)
Your animation must have 4 xml's like slide_down_in, slide_down_out, slide_up_in, slide_up_out, and use percentage like
slide_down_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="-100%"
android:toYDelta="0%"
android:duration="500" />
</set>
slide_down_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="500" />
</set>
slide_up_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:duration="500" />
</set>
slide_up_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="-100%"
android:duration="500" />
</set>
Its Working
Intent i = new Intent(getActivity(), FeedbackSuccessActivity.class);
i.putExtra("title", "Success!");
i.putExtra("message", "\n Profile Update Successfully \n ");
startActivity(i);
overridePendingTransition(R.anim.slide_down_in, R.anim.slide_down_out);
slide_down_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="-100%"
android:toYDelta="0%"
android:duration="500" />
</set>
slide_down_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0%"
android:toYDelta="100%"
android:duration="500" />
</set>