Android UI 开源库(1) AndroidSwipeLayout基础学习笔记

1.说明

AndroidSwipeLayout,Android平台上的滑动布局,又名刷卡布局,典型的应用就是侧滑删除与侧滑菜单。实现效果如qq的消息界面(如图1)。使用时直接将SwipeLayout视为一个ViewGroup控件,通过设置控件的layout_gravity属性即可控制下面的View显示时机(左划或右滑显示),使用十分简单方便。

ps:参考原文https://www.jianshu.com/p/58ed0a64e9b7

图1

2.使用步骤

2.1添加依赖

在build.gradle中添加SwipeLayout库的依赖,代码如下:

implementation "com.daimajia.swipelayout:library:1.2.0@aar"

2.2在xml布局文件中使用Swipe Layout

SwipeLayout的子标签中,最后一个子标签是SurfaceView,即不需通过滑动就可见的View,其他的子标签都是BottomView,即需要通过滑动才能显示在界面上。BottomView添加android:layout_gravity属性即可确定左划显示还是右滑显示。为简单起见,建议在SwipeLayout标签中放置3个LinearLayout子标签,分别代表左划显示的View、右滑显示的View、和正常显示的View。示例代码如下:

<?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="match_parent"
    tools:context=".MainActivity">

    <com.daimajia.swipe.SwipeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <!--右滑子标签-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_gravity="right"
            android:layout_height="wrap_content">
            <Button
                android:background="@color/colorPrimaryDark"
                android:id="@+id/button"
                android:text="删除"
                android:layout_width="100dp"
                android:layout_height="80dp" />
            <Button
                android:text="置顶"
                android:background="@color/colorAccent"
                android:layout_width="100dp"
                android:layout_height="80dp" />
        </LinearLayout>

        <!--左划子标签-->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_gravity="left"
            android:layout_height="wrap_content">
            <Button
                android:text="左划"
                android:layout_width="80dp"
                android:layout_height="80dp" />
        </LinearLayout>

        <!--SurfaceView-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp">
            <Button
                android:background="@color/green"
                android:layout_width="wrap_content"
                android:layout_height="80dp" />
            <Button
                android:background="@color/brown"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="80dp" />
        </LinearLayout>
    </com.daimajia.swipe.SwipeLayout>

</LinearLayout>

2.3运行

直接编译运行即可。

2.3运行效果

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值