列表条目左滑显示删除按钮的控件有很多,可以说是已经很常见了,不过下面这种效果的应该不常见,类似iOS11的但又有一点细节的差异,和iOS版微信首页列表的差不多。

使用: itemView的布局文件仿照下面即可
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/itemVisibleFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/default_selector_recycler_item"
android:focusable="true"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="@mipmap/ic_launcher"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:layout_marginEnd="10dp"
android:singleLine="true"
android:text="文本"
android:textColor="@android:color/black"
android:textSize="16sp"
tools:ignore="HardcodedText" />
</LinearLayout>
<FrameLayout
android:layout_width="1000dp"
android:layout_height="match_parent">
<!-- Put your menu itemViews here. The first one will be shown at the horizontal start. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/orange">
<Button
android:id="@+id/button_resetName"
android:layout_width="100dp"
android:layout_height="match_parent"
android:background="@null"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/resetName"
android:textColor="@android:color/white"
android:textSize="16sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red">
<Button
android:id="@+id/button_delete"
android:layout_width="85dp"
android:layout_height="match_parent"
android:background="@null"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/delete"
android:textColor="@android:color/white"
android:textSize="16sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/skyBlue">
<Button
android:id="@+id/button_top"
android:layout_width="85dp"
android:layout_height="match_parent"
android:background="@null"
style="?android:attr/buttonBarButtonStyle"
android:text="@string/top"
android:textColor="@android:color/white"
android:textSize="16sp"
tools:ignore="HardcodedText" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
这篇博客介绍了如何创建一个类似于iOS11风格,但又有细微差异的列表条目左滑菜单,其效果接近于iOS版微信首页的体验。通过自定义itemView的布局文件,你可以轻松实现这个功能。项目源码可在lzls/SwipeMenuRecyclerView找到。
475

被折叠的 条评论
为什么被折叠?



