如何扩展CardViews以显示更多细节,例如Google Keep卡? [英] How do I expand CardViews to show more detail like Google Keep cards?

查看:89
本文介绍了如何扩展CardViews以显示更多细节,例如Google Keep卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一些CardView,我希望它们的功能类似于Google Keep中的卡片.例如,当我单击包含文本的卡片时,它会随着动画扩展到另一个视图中.

I have some CardViews in my app and I want them to function like the cards in Google Keep. For example, when I click on a card that has text, it expands (with the animation) into another view.

如果不确定我的意思,请在Google Keep Android应用上创建记事,然后点击创建记事时显示的即时贴.这正是我想要在我的应用程序中发生的事情.

If you're not sure what I mean, create a note on the Google Keep Android app, tap on the card that appears when the note is created. This is exactly what I want to happen in my app.

我该怎么做?

推荐答案

棒棒糖的新功能!

活动+片段过渡

通过声明两个屏幕之间共有的共享元素",您可以在两个状态之间创建平滑过渡.

By declaring "shared elements" that are common across two screens you can create a smooth transition between the two states.

album_grid.xml:

album_grid.xml:

<ImageView
    …
    android:transitionName="@string/transition_album_cover" />

album_details.xml:

album_details.xml:

<ImageView
    …
    android:transitionName="@string/transition_album_cover" />

Java:

AlbumActivity.java
Intent intent = new Intent();
String transitionName = getString(R.string.transition_album_cover);
…
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
    albumCoverImageView,   // The view which starts the transition
    transitionName    // The transitionName of the view we’re transitioning to
    );
ActivityCompat.startActivity(activity, intent, options.toBundle());

在这里,我们在两个屏幕中定义了相同的transitionName.启动新的活动时,此过渡会自动设置为动画.除了共享元素,您现在还可以编排进入和退出元素.

Here we define the same transitionName in two screens. When starting the new Activity and this transition is animated automatically. In addition to shared elements, you can now also choreograph entering and exiting elements.

这篇关于如何扩展CardViews以显示更多细节,例如Google Keep卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆