我为片段做了一个共享元素转换。我的转换代码如下
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Transition changeTransform = TransitionInflater.from(this).
inflateTransition(R.transition.change_image_transform);
mainFragment.setSharedElementReturnTransition(changeTransform);
secondFragment.setSharedElementEnterTransition(changeTransform);
FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.addSharedElement(findViewById(R.id.button_view), "MyTransition");
fragmentTransaction
.replace(R.id.fragment_container, secondFragment, MainFragment.TAG);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
我的转换xml如下
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds />
<changeTransform />
</transitionSet>
我的mainFragment如下
```<?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">
<View
android:id="@+id/button_view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#00f"
android:transitionName="MyTransition"
android:onClick="clickButton"/>
</LinearLayout>
我的secondFragment如下
<?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">
<View
android:id="@+id/base_view"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<LinearLayout
android:layout_width="match_parent"
android:padding="20dp"
android:layout_height="100dp">
<View
android:id="@+id/button_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0f0"
android:transitionName="MyTransition"/>
</LinearLayout>
</LinearLayout>
从mainFragment顺利过渡到secondFragment。但是从secondFragment返回到mainFragment时,如果我在secondFragment中有base_view
,则转换才会正常。如果我从secondFragment中删除base_view
,则returnTransition不起作用。为什么要追加&#39;是否需要进行返回转换?
答案 0 :(得分:0)
经过一些实验,为了确保当 $("form").submit(function () {
if ($(this).valid()) { //<<< I was missing this check
$("#loading").show();
}
});
不再存在时,返回过渡动画仍然有效...使用base_view
代替layout_margin
,如下所示
padding