标签: shared-element-transition

找到所需的转换:MaterialContainerTransform?

在我的活动中,我尝试使用 MaterialContainerTransform 但它显示一个错误

找到所需的转换: MaterialContainerTransform

override fun onCreate(savedInstanceState: Bundle?) {
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
    setEnterSharedElementCallback(MaterialContainerTransformSharedElementCallback())
    //this is giving error
    window.sharedElementEnterTransition = MaterialContainerTransform().apply {
        addTarget(android.R.id.content)
        duration = 300L
    }
    window.sharedElementReturnTransition = MaterialContainerTransform().apply {
        addTarget(android.R.id.content)
        duration = 250L
    }
Run Code Online (Sandbox Code Playgroud)

我的依赖

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//material
implementation 'com.google.android.material:material:1.3.0-alpha02'

def coroutines_version = "1.3.8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
Run Code Online (Sandbox Code Playgroud)

}

android android-activity android-transitions material-design shared-element-transition

3
推荐指数
1
解决办法
1113
查看次数

2
推荐指数
1
解决办法
971
查看次数

从转换中排除 ViewGroup(除了一个特定的子级)

我试图从共享元素返回转换中排除一个视图组,比如说回收器视图。但问题是我不希望回收器视图的所有子级都排除在外,我希望特定的回收器视图子级包含转换。

Slide transition = new Slide(Gravity.END); 
transition.excludeTarget(recyclerView, true); 
transition.addTarget(ImageView.class); 
setExitTransition(transition); 
setReturnTransition(transition);
Run Code Online (Sandbox Code Playgroud)

我不明白为什么上面的代码不起作用。如果您有任何想法或任何方法来实现这一目标,请告诉我?

animation android android-animation android-transitions shared-element-transition

2
推荐指数
1
解决办法
2321
查看次数

如何在片段过渡中淡出非共享视图?

我目前正在试验带有片段的共享元素转换,并且基本思想正在发挥作用。我有两个非常相似的屏幕(见截图),共享转换适用于表单,但两个按钮(登录/社交)不能正常转换,它们在退出时消失,进入时重新出现。是否可以指定这两个视图项在过渡期间淡出和淡入?

片段A

 getActivity().getSupportFragmentManager().beginTransaction()
            .addSharedElement(btn_next, ViewCompat.getTransitionName(btn_next))
            .addSharedElement(et_email, ViewCompat.getTransitionName(et_email))
            .addSharedElement(ll_form, ViewCompat.getTransitionName(ll_form))
            .replace(R.id.fl_content, new LoginFragment())
            .addToBackStack(null)
            .commit();
Run Code Online (Sandbox Code Playgroud)

片段B

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setSharedElementEnterTransition(TransitionInflater.from(getContext()).inflateTransition(android.R.transition.move));
Run Code Online (Sandbox Code Playgroud)

截屏

android android-fragments shared-element-transition

2
推荐指数
1
解决办法
1093
查看次数

从 RecyclerView 到活动的共享元素转换不起作用

我想使用从RecyclerViewitem 到 another 的共享元素转换Activity,但它不起作用。该RecyclerView是内部的fragment,这也是onClick监听器RecyclerView项目

  @Override 
    public void onProductItemClick(int pos, PromoORProduct promoORProduct, ImageView shareImageView) {

    Intent intent = new Intent(getActivity(), ProductPreviewAct_.class);
    intent.putExtra("OBJECT", promoORProduct);
    intent.putExtra(ProductPreviewAct.SMALL_IMAGE_TRANSITION_NAME, "small_img" + pos);
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), shareImageView, "small_img" + pos);
    getActivity().startActivity(intent, options.toBundle());
}
Run Code Online (Sandbox Code Playgroud)

从我的适配器的 onBindViewHolder 调用侦听器

  @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ProductsViewHolder) {
            final PromoORProduct user = items.get(position);
            ProductsViewHolder userViewHolder = (ProductsViewHolder) holder;
                ViewCompat.setTransitionName(userViewHolder.imgSmall, "small_img"+position);
            holder.itemView.setOnClickListener(new View.OnClickListener() …
Run Code Online (Sandbox Code Playgroud)

android shared-element-transition android-recyclerview

2
推荐指数
1
解决办法
3128
查看次数

共享元素过渡图像视图变为白色

我正在使用 RecyclerView 到 ViewPager 共享元素转换。问题是当viewpager被分页到另一个图像时,返回到recyclerview后,第一个动画的imageview是白色的。

在此处输入图片说明

启动viewpager:

FragmentTransaction fragmentTransaction = getSupportFragmentManager()
            .beginTransaction()
            .setReorderingAllowed(true)
            .addSharedElement(view, name)
            .hide(recyclerFragment)
            .add(R.id.main_frameLayout, viewpagerFragment, tag)
            .commit();
Run Code Online (Sandbox Code Playgroud)

回到 recyclerview 片段:

FragmentTransaction fragmentTransaction = getSupportFragmentManager()
            .beginTransaction()
            .setReorderingAllowed(true)
            .addSharedElement(view, name)
            .remove(viewpagerFragment)
            .show(recyclerFragment)
            .commit();
Run Code Online (Sandbox Code Playgroud)

编辑:请注意,我知道位置并且我正在正确设置过渡名称。

android android-fragments shared-element-transition

2
推荐指数
1
解决办法
1513
查看次数

Android clears Activity to Activity shared element transition exit animation after pressing power button

I'm working on implementing a basic Activity transition animation with a shared element from a RecyclerView with a GridLayoutManager to a full screen details Activity screen. The animation works well under regular circumstances. So when clicking on an image in the grid it scales to the full screen image and on exiting the reverse happens. But if you press the power button and return to the app while the details screen is visible, Android seems to clear all registered shared …

animation android transition android-activity shared-element-transition

2
推荐指数
1
解决办法
499
查看次数

Android共享元素转换错误

正如您在此视频中看到的那样,我正在尝试为新活动的开放制作动画.在打开活动时,图像会正常动画,但在返回时会失败(我正在使用supportFinishAfterTransition())

我尝试了各种各样的方法,我在这里或谷歌上找到了,但没有任何效果,即:

在res/transition下定义转换:

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <changeBounds/>
    <changeImageTransform/>
</transitionSet>
Run Code Online (Sandbox Code Playgroud)

然后在主要活动的样式和我要打开的样式中使用它:

<!-- enable window content transitions -->
<item name="android:windowActivityTransitions">true</item>
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">
    @transition/change_image_transform</item>
<item name="android:windowSharedElementExitTransition">
    @transition/change_image_transform</item>
Run Code Online (Sandbox Code Playgroud)

我也在我的java代码中尝试过相同的东西:

getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setSharedElementExitTransition(...);
getWindow().setSharedElementEnterTransition(...);
Run Code Online (Sandbox Code Playgroud)

从我的观点持有人那里开始我的新活动:

private void openNewActivity() {
        String transitionName = "details";

        Intent intent = new Intent(mContext, ActivityCardDetails.class);

        ViewCompat.setTransitionName(mImageView, transitionName);

        //noinspection unchecked
        ActivityOptionsCompat options =
                ActivityOptionsCompat.makeSceneTransitionAnimation((MainActivity)mContext,
                        mImageView,   // The view which starts the transition
                        transitionName    // The transitionName of the view we’re transitioning to
                );


        ActivityCompat.startActivity((MainActivity) …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-transitions shared-element-transition

1
推荐指数
1
解决办法
2825
查看次数

返回活动之间的共享元素转换

我使用原生 Android Transition API 来制作 Activity 之间的过渡动​​画。这是我用来启动活动的来源:

        Intent intent = new Intent(MainActivity.this, DetailActivity.class);
        Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, imageView, imageView.getTransitionName()).toBundle();

        MainActivity.this.startActivity(intent, bundle);
Run Code Online (Sandbox Code Playgroud)

当我点击硬件后退按钮时,它会以预期的反向过渡动画返回到上一个活动,但是当我点击工具栏中的“向上”按钮时,它会以默认动画返回到上一个活动:

animation android android-animation android-transitions shared-element-transition

1
推荐指数
1
解决办法
1924
查看次数

Android:共享元素 - 返回转换不起作用

我实现了从回收器视图到片段之间的共享元素转换。输入转换效果很好,但我不知道为什么返回转换不起作用。

第一个片段中 RecyclerView 的适配器

public void onBindViewHolder(@NonNull final MenuItemViewHolder holder, int position)
{
  holder.setData(category, data.get(holder.getAdapterPosition()));
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
  {
    MenuItem item = data.get(holder.getAdapterPosition());
    ViewCompat.setTransitionName(holder.name, item.getName());
    ViewCompat.setTransitionName(holder.image, item.getImage());
    ViewCompat.setTransitionName(holder.price, item.getId());
  }

  holder.setViewClick(new View.OnClickListener()
  {
    @Override
    public void onClick(View v)
    {
      try
      {
        if (context != null)
        {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
          {
            showFragment(category, data.get(holder.getAdapterPosition()), holder.name, holder.price, holder.image, holder.isLoaded());
          }
          else
          {
            Gson gson = new Gson();
            Bundle bundle = new Bundle();
            bundle.putString(Values.CAT_DATA, gson.toJson(category));
            bundle.putString(Values.ITM_DATA, gson.toJson(data.get(holder.getAdapterPosition())));
            ((MainActivity) context).showFragment(ProductViewFragment.class, null, bundle);
          } …
Run Code Online (Sandbox Code Playgroud)

android android-animation shared-element-transition

1
推荐指数
1
解决办法
3143
查看次数

Android L过渡和主页按钮

我正在使用新的Android L转换,特别是共享元素转换以及Slide().当我按下后退按钮时,转换工作完美,它会将共享的ImageView滑动并转换到正确的位置,但是当我按下ActionBar中的home-up按钮时,它会忽略新的转换.

我在接收活动中设置了这段代码:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    getWindow().setExitTransition(new Slide());
    getWindow().setEnterTransition(new Slide());
Run Code Online (Sandbox Code Playgroud)

我的"主要"活动中的这段代码:

    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    Transition transition = new Slide();
    getWindow().setSharedElementEnterTransition(transition);
    getWindow().setSharedElementExitTransition(transition);
Run Code Online (Sandbox Code Playgroud)

android android-transitions shared-element-transition

0
推荐指数
1
解决办法
895
查看次数