Shared element not working

DimaArtsDimaArts RUMember
edited May 2016 in Xamarin.Android

In activity:

    protected override void OnCreate (Bundle savedInstanceState)
    {
        base.OnCreate (savedInstanceState);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.myButton);

        button.Click += delegate {
            button.Text = string.Format ("{0} clicks!", count++);
            ActivityOptionsCompat options = ActivityOptionsCompat.MakeSceneTransitionAnimation (this, button, "signbutton");
            Bundle bundle = options.ToBundle ();
        };
    }`

Main.axml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/myButton" android:transitionName="signbutton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

Why options.ToBundle () return null, but I am using android 5.1 device, and options is ActivityOptionsImpl21.

Tagged:

Posts

  • Ivan.0244Ivan.0244 USMember
    edited February 2016

    In my test app on android studio it is not null. Maybe bug in xamarin studio.

  • DimaArtsDimaArts RUMember
    edited May 2016

    To resolve this problem create library project on android studio with class:

    public class SharedElementHotFix
    {
    public Bundle sharedElementBundle(Activity activity, View view, String sharedelemname)
    {
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation (activity, view, sharedelemname);
            return options.toBundle ();
        }
    
        public Bundle sharedElementBundle(Activity activity, Pair<View, String> sharedelems)
        {
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation (activity, sharedelems);
            return options.toBundle ();
        }
    }
    

    In xamarin create binding library. And using next code:
    Bundle bundle = sharedelem.SharedElementBundle(this, butshowsignPanel, "signbutton");//options.ToBundle (); ActivityCompat.StartActivity(this, intent, bundle);

    It works!!! And bundle is not null. It is so bad, but I don't know better way.

  • LesterBotelloLesterBotello DOMember ✭✭

    Has anyone been able to fix this without using a hotfix that involves binding an external library? I'm trying to keep my app as small and reference-free as possible.

Sign In or Register to comment.