在Android中重新创建材料设计列表的问题

前端之家收集整理的这篇文章主要介绍了在Android中重新创建材料设计列表的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在一个滑动面板中重新创建 Android中的Material Design list: controls.

我正在使用:

> com.android.support:appcompat-v7
> com.android.support:support-v4
> com.android.support:recyclerview-v7
> com.android.support:design
> https://github.com/umano/AndroidSlidingUpPanel
> https://github.com/serso/android-linear-layout-manager
> https://github.com/daimajia/AndroidSwipeLayout
> https://github.com/tmiyamon/gradle-mdicons

我最终使用了支持库的一部分,但这个特定的应用程序只有5.0,所以我的代码中可能只有一些Lollipop的东西.

这是RecyclerView中列表项的布局:

  1. <com.daimajia.swipe.SwipeLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:layout_gravity="right">
  6. <RelativeLayout
  7. android:layout_width="42dp"
  8. android:layout_height="match_parent"
  9. android:background="?android:selectableItemBackground"
  10. android:clickable="true"
  11. android:focusable="true">
  12.  
  13. <ImageView
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_centerVertical="true"
  17. android:layout_centerHorizontal="true"
  18. android:src="@drawable/ic_delete_black_24dp"/>
  19.  
  20. </RelativeLayout>
  21.  
  22. <RelativeLayout
  23. android:id="@+id/surfaceView"
  24. android:layout_width="match_parent"
  25. android:layout_height="wrap_content"
  26. android:background="@drawable/ripple_floating"
  27. android:clickable="true"
  28. android:focusable="true"
  29. android:minHeight="48dp"
  30. android:paddingEnd="16dp"
  31. android:paddingStart="16dp"
  32. android:elevation="2dp">
  33.  
  34. <TextView
  35. android:id="@+id/name"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:layout_alignParentStart="true"
  39. android:layout_centerVertical="true"
  40. android:ellipsize="end"
  41. android:singleLine="true"
  42. android:text="..."/>
  43.  
  44. </RelativeLayout>
  45. </com.daimajia.swipe.SwipeLayout>

这是目前的结果.

剩下的问题是海拔阴影和分隔线.

正如您在图像中可以看到的,在列表项目的两侧有一些合理的阴影.然而,物品底部没有海拔阴影,所以当一个物品被揭露时,没有阴影显示在透明区域之上.

第二个问题是分隔线.我有一个单项目列表,没有图标/图像,所以正确的设计是使用分隔符的项目.

然而,我不能使用serso / android-linear-layout-manager中的DividerItemDecoration,因为它没有被集成到滑块中,当两个相邻的项目被滑动时,会发生这种情况.

有谁知道任何可绘制,属性或库,我应该用来将这些列表项作为具有海拔阴影和边框的材料表样式?

解决方法

阴影/高程

对于阴影/海拔看起来,您可以使用卡片视图与普通的技巧,使它们比屏幕宽度(“全宽卡”)稍宽.

例如:

  1. <android.support.v7.widget.CardView
  2. android:layout_width="match_parent"
  3. android:layout_height="72dp"
  4. android:layout_marginLeft="@dimen/card_margin_horizontal"
  5. android:layout_marginRight="@dimen/card_margin_horizontal"
  6. app:cardCornerRadius="0dp"
  7. app:cardElevation="4dp">

在值/ dimensions.xml中:

  1. <dimen name="card_margin_horizontal">-3dp</dimen>

在值-v21 / dimensional.xml中

  1. <dimen name="card_margin_horizontal">0dp</dimen>

分频器

而且,您可能不需要更改分隔线,它可能看起来不错.否则,尝试将分隔符添加到视图本身(顶视图或控制它的可见性).它可以只是一个高度为1dp和width match_parent的视图,backgroundColor设置为一些深灰色(或系统分隔符drawable(R.attr.listDivider)).

猜你在找的Android相关文章