I've implemented a transition between my activities, the problem is that when the transition occurs the content of the first activity is showing on the second one for a millisecond and then it disappears showing the content of the second activity, How can I get rid of that and smoothly show the second activity?
animation_enter:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
animation_leave:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
And that is how I'm calling it:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView clienteId = (TextView) view.findViewById(R.id.pedidoID);
Intent intent = new Intent(getActivity(), PedidoDetalheActivity.class);
intent.putExtra("id_pedido", clienteId.getText()); // envia o id do pedido para a tela de detalhes
startActivity(intent);
getActivity().overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);
}
});
So for your animations to work you have to do the following:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
This means that the activity will enter from left (100%) and will stop on the it's initial position (0%)
As for the leave animations:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"
/>
</set>
This means that the current visible activity will leave the screen from it's current position (0%) to the right (-100%)
Related
How create swipe to back?
In iOS:
[assembly: ExportRenderer(typeof(HIPSTO.Controls.CustomContentPage), typeof(HIPSTO.iOS.Platform.Renderers.IOSPageRenderer))]
namespace HIPSTO.iOS.Platform.Renderers
{
public class IOSPageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = true;
ViewController.NavigationController.InteractivePopGestureRecognizer.Delegate = new UIKit.UIGestureRecognizerDelegate();
}
}
}
But it only works from the edge. It is necessary from any place.
No ideas with android
As below shown:
First, You could achieved by NavigationPageRenderer in android.
This is GIF of this demo
TransitionNavigationPageRender.cs
[assembly: ExportRenderer(typeof(SwipePageDemo.Controls.TransitionNavigationPage), typeof(TransitionNavigationPageRenderer))]
namespace SwipePageDemo.Droid.Renderers
{
public class TransitionNavigationPageRenderer : NavigationPageRenderer
{
public TransitionNavigationPageRenderer(Context context) : base(context)
{
}
protected override void SetupPageTransition(Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
{
if (isPush)
{
}
else
{
transaction.SetCustomAnimations(Resource.Animation.enter_left, Resource.Animation.exit_right,
Resource.Animation.enter_right, Resource.Animation.exit_left);
}
}
}
}
enter_left.xml
<?xml version="1.0" encoding="utf-8" ?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="enter_from_left"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="300"/>
</set>
enter_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:fromYDelta="0%" android:toYDelta="0%"
android:duration="300" />
</set>
exit_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:fromYDelta="0%" android:toYDelta="0%"
android:duration="300"/>
</set>
exit_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="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="300" />
</set>
If you want to know more details about Page Transition , you could refer to this link.
https://github.com/jsuarezruiz/xamarin-forms-page-transitions
But it only works from the edge. It is necessary from any place
You could achieved it by threshold property of SwipeGestureRecognizer class
The SwipeGestureRecognizer class also includes a Threshold property, that can be optionally set to a uint value that represents the minimum swipe distance that must be achieved for a swipe to be recognized, in device-independent units. The default value of this property is 100, meaning that any swipes that are less than 100 device-independent units will be ignored. If you want to increase the area that can be swiped, you could reduce this data of Threshold like following code.
var leftSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Right };
leftSwipeGesture.Threshold = 50;
leftSwipeGesture.Swiped += (sender, e) => Navigation.PopAsync();
stackLayout.GestureRecognizers.Add(leftSwipeGesture);
I changed value of leftSwipeGesture.Threshold to 50, this is GIF of swipe.
I want to add animation to my registration page. I have 6 EditTexts and I want them to come one by one from right to left. I'm new to android, someone help me please.
Screenshot registration page
You can create your custom animation xmls and place inside anim folder inside resources folder:
left_swipe.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
right_swipe.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
You can start animation like :
RightAnim = AnimationUtils.loadAnimation(Screen.this, R.anim.right_swipe);
ScreenAnimation.startAnimation(RightAnim );
Plz make sure your animation xml file under res>anim
This is for slide_in_left
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-50%p" android:toXDelta="0"
android:duration="2500"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
and this is for slide_in_right
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
android:duration="2500"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="#android:integer/config_mediumAnimTime" />
</set>
in your java code
Animation a = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.slide_in_left);
a.reset();
etusername.clearAnimation();
etusername.startAnimation(a);
Animation b = AnimationUtils.loadAnimation(RegisterActivity.this, R.anim.slide_in_right);
b.reset();
etpassword.clearAnimation();
etpassword.startAnimation(b);
left to right animation:
leftToRight.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
right to left animation:
rightToLeft
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
write below code in your activity class
private Animation m_animationLeft;
private Animation m_animationRight;
m_animationLeft = AnimationUtils.loadAnimation(this, R.anim.leftToRight);
m_animationRight = AnimationUtils.loadAnimation(this, R.anim.rightToLeft);
editTextOne.startAnimation(m_animationLeft);
m_animationLeft.setAnimationListener(new AnimationListener()
{
#Override
public void onAnimationStart(Animation p_animation)
{
}
#Override
public void onAnimationRepeat(Animation p_animation)
{
}
#Override
public void onAnimationEnd(Animation p_animation)
{
// Start animation on another edittext . If you want to perform animation one by one edittext
}
});
}
}.start();
I've got repeatCount set as INFINITE (-1) and repeatMode set as RESTART (1)
http://developer.android.com/reference/android/view/animation/Animation.html#INFINITE
Even though my animation works, it doesn't repeat properly. What's missing in my code?
public class SyncActivity extends Activity {
Animation slideanim;
ImageView senoide;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_sync);
senoide = (ImageView) findViewById(R.id.imageView3);
slideanim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
//slideanim.setFillAfter(true);
slideanim.setRepeatCount(Animation.INFINITE);
slideanim.setRepeatMode(Animation.RESTART);
senoide.setAnimation(slideanim);
senoide.startAnimation(slideanim);
}
}
move.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-18.5%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="1000"/>
</set>
Change your XML to have the repeat mode and count on it:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-18.5%"
android:fromYDelta="0%" android:toYDelta="0%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:duration="1000"/>
</set>
I want to slide from left to right (opposite right to left in this code below). My current task is running correctly on button click.
Here is the source:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnopen = (Button)findViewById(R.id.btnWindowAnimation);
btnopen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
Bundle bundle =ActivityOptions.makeCustomAnimation(getApplicationContext(), ` `R.anim.animation,R.anim.animation2).toBundle();
startActivity(i, bundle);
}
});
}
Here Animation 1:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>
Here Animation 2:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-50%p"
android:duration="500"/>
This is for left to right animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
This is for right to left animation:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700" />
</set>
Check this link.
Here is the first answer:
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:duration="500"/>
</set>
And here is the second XML:
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="500" />
</set>
I am trying to do a slide animation between two Activities when then one starts the other,
public void onClick(View view) {
Intent intent = new Intent(TestAppActivity.this, SecondActivity.class);
startActivityForResult(intent, 1);
TestAppActivity.this.overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);
finish();
}
There is no animation at all. The xmls are, for enter:
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="3000" />
And for leave:
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="3000" />
I can see what is gong wrong here. Using Android 2.3.3. Thanks.
Put the overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave); after finish();.
To do an animation where the first activity go to the left and the second activity enters from the right :
slide_out_left.xml :
<?xml version="1.0" encoding="utf-8"?>
<!--
Animation : Perform animation : Out - Direction : Left
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="0"
android:toXDelta="-100%p" />
</set>
slide_in_right.xml :
<?xml version="1.0" encoding="utf-8"?>
<!--
Animation : Perform animation : In - Direction : Right
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="400"
android:fromXDelta="100%p"
android:toXDelta="0" />
</set>
Note : you can change android:duration if you want.
And you have to add this code :
public void onClick(View view) {
Intent intent = new Intent(TestAppActivity.this, SecondActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
finish();
}