Dan*_*sen 11 android android-layout material-design android-recyclerview
我想在滑动面板中重新创建Material Design 列表: Android中的控件.
我正在利用:
我最终使用了部分支持库,但这个特定的应用程序只有5.0+,所以我的代码中可能只有一些Lollipop.
这是我的RecyclerView中列表项的布局:
<com.daimajia.swipe.SwipeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right">
<RelativeLayout
android:layout_width="42dp"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:clickable="true"
android:focusable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_delete_black_24dp"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_floating"
android:clickable="true"
android:focusable="true"
android:minHeight="48dp"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:elevation="2dp">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:ellipsize="end"
android:singleLine="true"
android:text="..."/>
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
Run Code Online (Sandbox Code Playgroud)
这是目前的结果.
要解决的其余问题是高程阴影和分隔线.
正如您在图像中看到的那样,列表项的两侧有一些合理的阴影.但是项目底部没有高度阴影,因此当显示项目时,在显示区域上方没有阴影.
第二个问题是分隔线.我有一个没有图标/图像的单项列表,所以正确的设计是使用项目的分隔符.
但是我不能使用serso/android-linear-layout-manager中的DividerItemDecoration,因为它没有集成到滑块中,当滑动了2个相邻的项目时会发生这种情况.

有没有人知道我应该使用任何drawable,属性或库来将这些列表项设置为具有高程阴影和边框的材料表?
Shadows/Elevation
For the shadows/elevation to look like that you can use card view with the common trick to make them slightly wider than the screen width ("full width cards").
For example:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_marginLeft="@dimen/card_margin_horizontal"
android:layout_marginRight="@dimen/card_margin_horizontal"
app:cardCornerRadius="0dp"
app:cardElevation="4dp">
Run Code Online (Sandbox Code Playgroud)
In values/dimens.xml:
<dimen name="card_margin_horizontal">-3dp</dimen>
Run Code Online (Sandbox Code Playgroud)
In values-v21/dimens.xml
<dimen name="card_margin_horizontal">0dp</dimen>
Run Code Online (Sandbox Code Playgroud)
Divider
这样你可能就不需要改变分隔线了,看起来可能还不错。否则,请尝试将分隔线添加到视图本身(顶视图或自己控制其可见性)。它可以只是一个高度为 1dp、宽度为深灰色的视图match_parent(backgroundColor或系统分隔线可绘制 ( R.attr.listDivider))。