我的应用程序曾经具有从片段到活动的共享元素过渡。我不确定它何时停止工作。我已经进行了较小的代码更改,但是没有任何影响过渡周围的代码。我做的最大的事情是将支持库更新为v24.2.1(来自v23.3.0)。我想知道我是否只是忽略了一些愚蠢的东西,还是支持库更改有所作为。相关代码片段如下:
启动共享元素过渡的代码:
public void PreviewClicked(object sender, EventArgs e)
{
var intent = new Intent(Activity, typeof(RoutineActivity));
intent.PutExtra(RoutineBundleKeys.BLOB_ID, _selectedBlobId.ToString());
intent.PutExtra(RoutineBundleKeys.ROUTINE_TITLE, _selectedTitle);
intent.PutExtra(RoutineBundleKeys.ROUTINE_HTML, ViewModel.Html);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
_selectedPreview.TransitionGroup = true;
ActivityOptionsCompat options = ActivityOptionsCompat.MakeSceneTransitionAnimation(Activity,
_selectedPreview,
"webview_preview_transition");
StartActivity(intent, options.ToBundle());
}
else
{
StartActivity(intent);
}
}
和正在共享的XML元素(上面的摘要中的_selectedPreview):
<WebView
android:id="@+id/routine_preview"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="center_vertical"
android:scrollbars="none"
android:transitionName="webview_preview_transition" />
整理活动中的on创作方法:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.routine_activity_layout);
_routineTitle = Intent.GetStringExtra(RoutineBundleKeys.ROUTINE_TITLE);
var titleToolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.doc_title_toolbar);
SetSupportActionBar(titleToolbar);
SupportActionBar.Title = _routineTitle;
_htmlString = Intent.GetStringExtra(RoutineBundleKeys.ROUTINE_HTML);
if (_htmlString != null)
{
_routineView = FindViewById<WebView>(Resource.Id.routine_frame);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
_routineView.TransitionGroup = true;
}
_routineView.Settings.BuiltInZoomControls = true;
_routineView.Settings.DisplayZoomControls = false;
string mimeType = "text/html";
string encoding = "UTF-8";
_routineView.LoadDataWithBaseURL("", _htmlString, mimeType, encoding, "");
}
else
{
var blobIdString = Intent.GetStringExtra(RoutineBundleKeys.BLOB_ID);
_blobId = new Guid(blobIdString);
RoutineFragment routineFragment = new RoutineFragment(_blobId);
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.routine_frame, routineFragment).Commit();
}
}
和此活动的XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nothing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/doc_title_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<WebView
android:id="@+id/routine_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="webview_preview_transition" />
</LinearLayout>
在我的基本主题中,我确实有 <item name="android:windowContentTransitions">true</item>
我不知所措。似乎一切都正确设置了。
编辑2017年2月2日:Xamarin开发人员已确认这是一个错误。
我永远无法实现此功能,但我怀疑这可能是Xamarin错误。我在AndroidSupportComponents问题跟踪器上发现了这个错误。显然是在支持库的RC1中找到的,但我没有看到任何开发人员响应。