侧滑置顶,取消置顶

news/2024/9/2 2:26:30 标签: android-studio, kotlin, android

第一步:布局

<?xml version="1.0" encoding="utf-8"?>
<com.ddmh.magic.camera.ui.widget.SwipeMenuLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_marginTop="12dp"
    android:clickable="true"
    app:ios="false"
    app:leftSwipe="true"
    app:swipeEnable="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/cst_out"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/tv_team_name_short"
            android:layout_width="60dp"
            android:layout_height="match_parent"
            android:background="@drawable/bg_5493f7_4radius"
            android:gravity="center"
            android:text="xxxx"
            android:textColor="#ffffffff"
            android:textSize="18sp"
            app:layout_constraintLeft_toLeftOf="parent" />

        <TextView
            android:id="@+id/tv_top_tips"
            android:layout_width="32dp"
            android:layout_height="18dp"
            android:background="@drawable/bg_e0e0e0_4radius"
            android:gravity="center"
            android:text="置顶"
            android:textColor="#ff878f99"
            android:textSize="10sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tv_team_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:ellipsize="end"
            android:maxWidth="250dp"
            android:singleLine="true"
            android:text="xxx"
            android:textColor="#ff1d2129"
            android:textSize="16sp"
            app:layout_constraintBottom_toTopOf="@+id/tv_team_day"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintLeft_toRightOf="@+id/tv_team_name_short"
            app:layout_constraintTop_toTopOf="@+id/tv_team_name_short" />


        <TextView
            android:id="@+id/tv_admin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:background="@drawable/bg_ff615d_2radius"
            android:paddingLeft="7dp"
            android:paddingTop="5dp"
            android:paddingRight="7dp"
            android:paddingBottom="5dp"
            android:text="主xx员"
            android:textColor="#ffff615d"
            android:textSize="10sp"
            app:layout_constraintLeft_toRightOf="@+id/tv_team_name"
            app:layout_constraintTop_toTopOf="@+id/tv_team_name" />


        <ImageView
            android:id="@+id/tv_team_day"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_today"
            app:layout_constraintBottom_toBottomOf="@+id/tv_team_name_short"
            app:layout_constraintLeft_toLeftOf="@+id/tv_team_name"
            app:layout_constraintTop_toBottomOf="@+id/tv_team_name" />

        <TextView
            android:id="@+id/tv_takephots_peoples"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_4"
            android:text="xxxx"
            android:textColor="#ff878f99"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="@+id/tv_team_day"
            app:layout_constraintLeft_toRightOf="@+id/tv_team_day"
            app:layout_constraintTop_toTopOf="@+id/tv_team_day" />

        <TextView
            android:id="@+id/tv_pic_num"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="xxx"
            android:textColor="#ff878f99"
            android:textSize="12sp"
            app:layout_constraintBottom_toBottomOf="@+id/tv_takephots_peoples"
            app:layout_constraintLeft_toRightOf="@+id/tv_takephots_peoples"
            app:layout_constraintTop_toTopOf="@+id/tv_takephots_peoples" />


    </androidx.constraintlayout.widget.ConstraintLayout>


    <LinearLayout
        android:id="@+id/ll_top"
        android:layout_width="90dp"
        android:layout_height="match_parent"
        android:background="@color/color_gray"
        android:gravity="center">

        <TextView
            android:id="@+id/tv_top"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="置顶"
            android:textColor="@color/white"
            android:textSize="16sp" />
    </LinearLayout>
</com.ddmh.magic.camera.ui.widget.SwipeMenuLayout>

第二步:适配器

class TeamItemAdapter(var list: ArrayList<TeamListBean>?) :
    BaseQuickAdapter<TeamListBean, BaseViewHolder>(R.layout.item_team_member, list) {

    override fun convert(holder: BaseViewHolder, item: TeamListBean) {
        holder.setText(R.id.tv_team_name_short, CommonUtils.getBeforeTwoStr(item.teamName))
        holder.setText(R.id.tv_team_name, item.teamName)
        holder.setText(R.id.tv_takephots_peoples, "已xx数:2")
        holder.setGone(R.id.tv_top_tips, !item.topFlag)
        holder.setText(R.id.tv_pic_num, "照片:2")
        when (item.roleType) {
            1 -> {
                holder.setText(R.id.tv_admin, "主管理员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.color_ff615d)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_ff615d_2radius)
            }
            2 -> {
                holder.setText(R.id.tv_admin, "管理员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.color_f2a649)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_1af2a649_2radius)
            }
            3 -> {
                holder.setText(R.id.tv_admin, "成员")
                holder.setTextColor(
                    R.id.tv_admin,
                    AppContext.appContext.resources.getColor(R.color.font_39ba81)
                )
                holder.setBackgroundResource(R.id.tv_admin, R.drawable.bg_39ba81_2radius)
            }
        }
        var tvTop = holder.getView<TextView>(R.id.tv_top)
        tvTop.text = if (item.topFlag) {
            "取消置顶"
        } else {
            "置顶"
        }
        if (item.topFlag) {
            holder.setBackgroundColor(
                R.id.ll_top,
                AppContext.appContext.resources.getColor(R.color.color_ff615d)
            )
        } else {
            holder.setBackgroundColor(
                R.id.ll_top,
                AppContext.appContext.resources.getColor(R.color.font_c9cdd4)
            )
        }
    }
}

第三步:代码

mTeamAdapter.addChildClickViewIds(R.id.tv_top, R.id.cst_out)
mTeamAdapter.setOnItemChildClickListener { adapter, view, position ->
    val bean = adapter.data[position] as TeamListBean
    when (view.id) {
        R.id.tv_top -> {
            bean.topFlag = !bean.topFlag
      adapter.notification
        }

        R.id.cst_out -> {
           
        }
    }

}


http://www.niftyadmin.cn/n/4931943.html

相关文章

【学习FreeRTOS】第6章——FreeRTOS中断管理

【本篇文章的也可参考STM32中断文章http://t.csdn.cn/foF9I&#xff0c;结合着学习效果更好】 1.什么是中断 中断&#xff1a;让CPU打断正常运行的程序&#xff0c;转而去处理紧急的事件&#xff08;程序&#xff09;&#xff0c;就叫中断中断执行机制&#xff0c;可简单概括…

【02】基础知识:typescript数据类型

1、布尔类型 boolean let flag: boolean false2、数字类型 number let num: number 6 //十进制 let num2: number 0xf00d //十六进制 let num3: number 0b1010 //二进制 let num4: number 0o744 //八进制3、字符串类型 string 用双引号&#xff08;“&#xff09;或单引…

JavaScript中常用处理对象的方法

一.方法 Object.keys(obj) 返回一个包含对象自身所有属性名称的数组。 let person {firstName: "John",lastName: "Doe" }; let keys Object.keys(person); console.log(keys); // 输出: ["firstName", "lastName"]Object.values…

chrome V3 插件开发 基础

目录 准备popup通信popup 发消息给 backgroundpopup 发消息给 content长期连接 如何页面上添加一个按钮&#xff1f;tabs.onUpdatedcontent-script.jsinject.js 右键菜单chrome.contextMenus举个例子添加关于报错&#xff08;cannot create item with duplicate id XXX&#xf…

计算机网络:网络字节序

目录 一、字节序1.字节序概念2.字节序的理解&#xff08;1&#xff09;大端模式存储数据&#xff08;2&#xff09;小端模式存储数据 二、网络字节序 一、字节序 1.字节序概念 字节序&#xff1a;内存中存储多字节数据的顺序。 难道存储数据还要看顺序吗&#xff1f; yes。内…

『CV学习笔记』docker和nvidia-docker离线安装

docker和nvidia-docker离线安装 文章目录 1. docker的deb包下载链接2. nvidia-docker 的deb包下载3. 重启 docker4. 检验安装5. Docker容器命令行不支持Tab键命令自动补全6. 参考文献这里是ubuntu操作系统, 如果是其他的操作系统,则需要安装对应的deb包1. docker的deb包下载链…

【雕爷学编程】Arduino动手做(24)---水位传感器模块3

37款传感器与模块的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&#x…

《Zookeeper》源码分析(七)之 NIOServerCnxn的工作原理

目录 NIOServerCnxnreadPayload()handleWrite(k)process() NIOServerCnxn 在上一节IOWorkRequest的doWork()方法中提到会将IO就绪的key通过handleIO()方法提交给NIOServerCnxn处理&#xff0c;一个NIOServerCnxn代表客户端与服务端的一个连接&#xff0c;它用于处理两者之间的…