How can I reduce the entry and exit animation speed of BottomSheetDialogFragment? - android

I am not sure is this can be acheived using setEnterTransition() and setExitTransition() methods.

I solved using StyleAnimation
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (getDialog() != null && getDialog().getWindow() != null)
getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
}
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="100%p"
android:toYDelta="0"
android:duration="3000"/> <!--Define duration here-->
</set>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="100%p"
android:duration="5000"/> <!--Define duration here-->
</set>

I think I got the answer:
I can use getDialog().getWindow().setWindowAnimations() method to achieve the same.

Related

How to hide layout with right to left translation

I want to hide a layout on click button with right to left animation. I have already added animation to same layout while appearing the view. Now I want to hide that view with animation.
//on appearing view
Animation anim = AnimationUtils.loadAnimation(this, R.anim.left_to_right);
mylayout.startAnimation(anim1);
Now I want to hide same layout with rigth to left animation. And then I want to set visibility GONE.
You can make a animation resource and using on your startActivity
Activity
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
overridePendingTransition(R.anim.right_left_in, R.anim.right_left_out);
finish();
animation res----> ../anim/right_left_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
animation res----> ../anim/right_left_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%p"
android:toXDelta="100%p">
</translate>
==========================
OTHERS ANIMATION
../anim/move_left_in_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="-100%p"
android:toXDelta="0%p">
</translate>
../anim/move_left_out_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
../anim/slid_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
../anim/slid_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
../anim/zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="3"
android:toYScale="3" >
</scale>
</set>
You can make same XML for animation Right to left and then apply animation same as you did and add animation listener like below, and just set Visibility gone to your view in onAnimationEnd
anim .setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
Create "anim" Android resource directory below res folder :
Then create new anim file called slide_left_out.xml and write this code :
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together"
android:duration="350">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:fromYDelta="0"
android:toYDelta="50%p"/>
<scale
android:fromXScale="1"
android:toXScale="0.5"
android:fromYScale="1"
android:toYScale="0.5"/>
<alpha
android:fromAlpha="1"
android:toAlpha="0"/>
</set>
Then apply the animation to the view
Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_left_out);
mylayout.startAnimation(anim);

Android - How to open an acitivity with the scale and fade effect

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.

Is there a way to slide between Activities without the black gap?

I'm trying to create an Android app, and switch between activities with a slide, when the previous activity slides out to the right, and the new activity comes in the left.
I can do somethibg like this, with:
Intent intent = new Intent(getContext(), NextActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.in_ltr, R.anim.out_ltr);
Where the in_ltr.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="-100%p"
android:toXDelta="0"
android:duration="700"
/>
</set>
And the out_ltr.xml is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="#android:anim/accelerate_decelerate_interpolator">
<translate
android:fromXDelta="0"
android:toXDelta="100%p"
android:duration="500"
/>
</set>
It's almost perfect, but a small black gap appers between the two activity during the animation. You can see it here on YouTube.
I've tried anything I found in the Google in the last hour, but nothing seems to remove that gap. Is it possible to remove that gap?
Thanks!
Try to set Alpha with translate effect....
Try This...
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:interpolator/accelerate_cubic">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="400" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.3"
android:duration="500" />
</set>
Add this two file in res/anim folder.
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="#android:integer/config_longAnimTime"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
And write the following code in onCreate() method of next activity that you pass through the Intent.
overridePendingTransition(r.anim.slide_in, R.anim.slide_out);
hope it will remove your space
Try this: create a RootActivity.java and extend it in your activity.
import android.app.Activity;
import android.os.Bundle;
public class RootActivity extends Activity {
int onStartCount = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
onStartCount = 1;
if (savedInstanceState == null) // 1st time
{
this.overridePendingTransition(R.anim.anim_slide_in_left,
R.anim.anim_slide_out_left);
} else // already created so reverse animation
{
onStartCount = 2;
}
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
if (onStartCount > 1) {
this.overridePendingTransition(R.anim.anim_slide_in_right,
R.anim.anim_slide_out_right);
} else if (onStartCount == 1) {
onStartCount++;
}
}
}
add these animations to anim folder:
anim_slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
</set>
anim_slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>
anim_slide_out_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
</set>
anim_slide_out_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="600"
android:fromXDelta="0%"
android:toXDelta="-100%" >
</translate>
</set>
Try to add below item into your AppTheme
<item name="android:windowIsTranslucent">true</item>
Sorry guys, I was very, very stupid.
I changed the duration to the same amount of time, and the gap disappeared.

Custom animation on up navigation

When I instanciate a new Activity is use a custom animation like this:
Intent registerIntent = new Intent();
registerIntent.setClassName(getPackageName(), getPackageName() + ".activity.RegisterActivity");
startActivity(registerIntent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
This way the current/old activity slides out to the left, while the new activity slides in from the right.
When in the new RegisterActivity I use following code to handle the animation when the user uses the "Back" button:
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
Now the current activity leaves to the right and the old activity (from before) comes back in from the left.
I also tried to handle the "Up" Navigation like this, but with no result:
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
return super.onOptionsItemSelected(item);
}
How would i use a custom animation on "Up" navigation? Any suggestions on how to better use animations?
EDIT:
slide_in_left.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="500" />
</set>
slide_out_right.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="500" />
</set>
I changed the following: Now it works:
Old:
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.blue)));
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
New:
getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.blue)));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
If I understood... I think that this resolve.
Intent registerIntent = new Intent();
registerIntent.setClassName(getPackageName(), getPackageName() + ".activity.RegisterActivity");
startActivity(registerIntent);
overridePendingTransition(
R.anim.animation_in+right_to_left,
R.anim.animation_out_right_to_left);
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.animation_in_left_to_right,
R.anim.animation_out_left_to_right);
}
animation_in_left_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:duration="500"/>
</set>
animation_out_left_to_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="200%"
android:duration="500"/>
</set>
animation_in_right_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="200%" android:toXDelta="0%"
android:duration="500"/>
</set>
animation_out_right_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0" android:toXDelta="-100%"
android:duration="500" />
</set>
you use the same logic to UP navigation

Android:ViewFlipper animation

I have add a ViewFlipper in which has 2 linearlayout,and I have made an animation xml:
left_in.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="3000"/>
</set>
right_out.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="3000"/>
</set>
left_out.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="3000"/>
</set>
right_in.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="3000"/>
</set>
the "Next" button in one linearlayout which shows when first load the app:
mNext.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
mViewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper1);
//mViewFlipper.setAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_out));
mViewFlipper.showNext();
}
});
and the "Prev" button:
mPrev.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
mViewFlipper = (ViewFlipper)findViewById(R.id.viewFlipper1);
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_in));
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_out));
mViewFlipper.showPrevious();
}
});
The "Next" Button goes well, But the "Prev" Button goes strange: when I click the "prev",it first change into the previous view and then start the animation ,and at last it changes into the Previous view again! How to solve it??
Thanks in advance!!
You want to use setOutAnimation() and setInAnimation().
Well this a very old post. but still the fix is here:
you need to call viewFlipper.setOutAnimation(null) and viewFlipper.setInAnimation(null) to reset the animation .
#Override
public void onClick(View v)
{
if (v.equals(mNext))
{
mViewFlipper.setOutAnimation(null);
mViewFlipper.setInAnimation(null);
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
vf.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_out));
mViewFlipper.showNext();
}
else if (v.equals(mPrev))
{
mViewFlipper.setOutAnimation(null);
mViewFlipper.setInAnimation(null);
mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_in));
mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_out));
mViewFlipper.showPrevious();
}
}

Categories

Resources