I saw an app, whose icon behavior in the navigationView delay it's visibility (Fade In- animation), yet my API for phone is 19.
My question is, how can I access to these icons to delay its visibility? Is it possible to implement it without using third party library?
For your view in Java you can do something like this -
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
AnimationSet animation = new AnimationSet(false); //change to false
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
View.startAnimation(animation);
If you want to use only one if you wish to.
You can even stop it by calling clearing it
View.clearAnimation();
OR other way
For XML, in your res/anim folder make a file, suppose name is 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>
And in java
Animation animationFadeIn = AnimationU
tils.loadAnimation(this, R.anim.fadein);
View.startAnimation(animationFadeOut);
Use startAnimation() in a method where navigation becomes visible
Related
My target is to animate current view from it's current position(center), to top border of it's parent. Is that possible? I have already tried next code, but the problem is that my view disappears after animation:
Animation bottomUp = AnimationUtils.loadAnimation(context, R.anim.bottom_up);
popup.startAnimation(bottomUp);
and
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%"
android:toYDelta="0%"
android:fillAfter="true"
android:duration="500"/>
</set>
That can easily be done in Java with ViewPropertyAnimator
popup.animate().translationY(0).setDuration(500); // 0 is top of Y axis
The animation always starts at the current position.
Check the ViewPropertyAnimator docs for future animations, it's very easy to use and can save you a lot of code.
i have a transition animation xml
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="400"/>
</set>
I want to apply this animation on several items but with varying duration. I'm trying to dynamically change duration by calling setDuration and then calling startAnimation.
mSlideLeft.setDuration(400);
view1.startAnimation(mSlideLeft);
mSlideLeft.setDuration(500);
view2.startAnimation(mSlideLeft);
mSlideLeft.setDuration(600);
view3.startAnimation(mSlideLeft);
but all view animation in same duration. How do I dynamically change duration of animation?
You're using the same Animation object for all three Views. So you're calling setDuration on the same object 3 times.
You need to create three separate Animation objects if you want to use three different durations.
Animation firstSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
firstSlideLeft.setDuration(400);
view1.startAnimation(firstSlideLeft);
Animation secondSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
secondSlideLeft.setDuration(500);
view2.startAnimation(secondSlideLeft);
Animation thirdSlideLeft = AnimationUtils.loadAnimation(context, R.anim.slide_left);
thirdSlideLeft.setDuration(600);
view3.startAnimation(thirdSlideLeft);
I would like to use a right-to-left sliding animation when transitioning between two activities. So far, I have set up a command to pass to the next activity.
public void advancenext (View view) {
Intent intent = new Intent(Prompt1.this, Prompt2.class);
Prompt1.this.startActivity(intent);
}
However, I am having trouble incorporating the animation into this code. This is what I have so far for the translation animation
Animation set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
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(500);
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.25f);
How would I go about combining the animation information with the activity change?
Thanks in advance
To set up an activity entrance animation, you must create a tween animation (involving alpha, scale, translate, &c) in the res\anim folder and then call overridePendingTransition() just after invoking startActivity().
For example, you could get an "activity enters from right and pushes the previous one out" effect (which if I understood correctly is what you need) with these animation files:
push_left_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
push_left_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
It's advisable to set up a "reverse" animation when finishing the activity, so effect when the back button is pressed is coherent with the entrance.
I'm trying to implement a simple animation effect for login screen.
Here's the scenario,
1: Some text and a login button will be displayed by default.
2: After clicking the login button a new frame layout will appear from bottom to top. This layout will prompt user to enter their username and password.
I can make an animation which will overlay from one parent to another. In this scenario, I'm looking for an animation that will appear without leaving the activity.
First set invisible to your layout.
Set animation to slideUp and slideDown.
final LinearLayout layout = (LinearLayout)findViewById(R.id.yourlayout);
button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
if(layout.getVisibility()==View.INVISIBLE){
layout.startAnimation(slideUp);
layout.setVisibility(View.VISIBLE);
}
});
slide_up.xml (create in res/anim directory)
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:fromYDelta="500" android:duration="500"/>
</set>
slide_down.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:fromYDelta="0" android:toYDelta="500" android:duration="500"/>
</set>
Note:
You should edit values in slide_down.xml and slide_up.xml until get favorable result.for example:change android:fromYDelta="500" to android:fromYDelta="700"
Check out this tutorial, it explains some basic animations which you can customize for your need.
http://www.androidhive.info/2013/06/android-working-with-xml-animations/
My GOAL is to implement custom toast in my application as follows:
MyCustomToastClass.makeText(context,View,anyDurationInMS);
I want to set the "Toast" gravity, Layout, duration(not just Length.SHORT/LONG)
Things i've tried so far:
Class with windowManager object
problem was it must implement android system animation in:
params.windowAnimations
and when I tried to implement my custom animation as followed:
windowManager.addView(mLayout);
Animation AlphaAnimation = new ...
it didn't implement my animation.
Class with the rootView element to add the Toast's layout to it:
In this way I succeeded to implement everything only when the root view was FrameLayout type (With other layout I couldn't set the "Toast" gravity to center).
I would appreciate if someone has implemented this feature, Or to guide me if i'm missing something in one of my ways.
thanks
Sorry for misunderstand your question
if you want to create an pop up like toast and the duration is up to you maybe you can try to create a custom view that will contain the content you want to be toasted after that you can place your main layout in the frame layout then everytime the user trigger your custom toast you can add the custom view to your frame layout so it'll be positioned in front of your main layout and for fade in fade out animation you can use this
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
fadeIn.setDuration(1000);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
fadeOut.setStartOffset(1000);
fadeOut.setDuration(1000);
or if you want to use XML
FadeIn
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha= 1.0"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
FadeOut
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000"
android:repeatCount="infinite"
android:repeatMode="reverse"
/>
and for the time you can use
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
// FADE OUT THE POP UP/TOAST HERE
}
}, /*SET THE TIME HERE*/);
I hope this answer is clear enough for you
and if you still have some question about my answer don't hesitate to ask in the comment :)