如何在列表视图中创建 Google + 卡片 UI? [英] How to create Google + cards UI in a list view?
问题描述
我想创建一个卡片列表视图,但是在阅读了这篇博文后 goolge-plus-layout,我的卡片是任何列表的可行解决方案.动画部分似乎太占用内存,无法同时加载超过 40 个元素的列表视图.
I want to create a listView of cards, but after reading this blog post goolge-plus-layout, I'm cards are a viable solution for a list of anything. The animation part seems too memory intensive to load say a listview with more than 40 elements simultaneously.
有没有更好的方法可以在 listView 中实现卡片 UI?
Is there a better way to achieve a cards UI in listView?
推荐答案
您可以创建自定义可绘制对象,并将其应用于您的每个列表视图元素.
You can create a custom drawable, and apply that to each of your listview elements.
我在我的 UI 中将这个用于卡片.我不认为这种方法存在重大的性能问题.
I use this one for cards in my UI. I don't think there is significant performance issues with this approach.
可绘制代码(在 drawableig_card.xml 中)如下所示:
The drawable code (in drawableig_card.xml) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/second_grey" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="rectangle" >
<corners android:radius="3dp" />
<solid android:color="@color/card_shadow" />
</shape>
</item>
<item
android:bottom="12dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="rectangle" >
<corners android:radius="3dp" />
<solid android:color="@color/card_white" />
</shape>
</item>
</layer-list>
我将背景应用到我的列表视图元素中,如下所示:
I apply the background to my listview elements like this:
<ListView
android:id="@+id/apps_fragment_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/big_card" />
如果你想把它作为背景添加到任何 View(不仅仅是一个列表),你只需使 View 的背景元素的自定义可绘制:
If you want to add this as a background to any View (not just a list), you just make the custom drawable that View's background element:
<TextView
android:id="@+id/any_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/big_card" />
这篇关于如何在列表视图中创建 Google + 卡片 UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!