我想重新创建 Material Design list: controls在 Android 中的滑动面板内。
我正在使用:
- com.android.support:appcompat-v7
- com.android.support:support-v4
- com.android.support:recyclerview-v7
- com.android.support:设计
- 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 中列表项的布局:
<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>
这是当前的结果。
剩下的问题是高程阴影和分隔线。
正如您在图片中看到的,列表项的两侧有一些合理的阴影。但是,项目底部没有高程阴影,因此当项目显示时,显示区域上方不会显示阴影。
第二个问题是分频器。我有一个没有图标/图像的单项列表,因此正确的设计是对项目使用分隔符。
但是我不能使用 serso/android-linear-layout-manager 中的 DividerItemDecoration,因为它没有集成到 slider 中,当滑动 2 个相邻的项目时会发生这种情况。
有谁知道我应该使用任何可绘制对象、属性或库来将这些列表项设置为具有高程阴影和边框的 Material 表?
最佳答案
阴影/高程
要使阴影/高程看起来像那样,您可以使用带有常用技巧的卡片 View ,使它们略宽于屏幕宽度(“全宽卡片”)。
例如:
<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">
在值/dimens.xml 中:
<dimen name="card_margin_horizontal">-3dp</dimen>
在 values-v21/dimens.xml 中
<dimen name="card_margin_horizontal">0dp</dimen>
分隔线
有了它,您可能不需要更改分隔线,它可能看起来没问题。
否则尝试将分隔线添加到 View 本身(顶 View 或自己控制它的可见性)。它可以只是一个高度为 1dp 和宽度 match_parent
和 backgroundColor
设置为一些深灰色的 View (或者系统分隔线可绘制(R.attr.listDivider
).
关于android - 在 Android 中重新创建带有 leave behind 的 Material 设计列表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32235461/