侧滑置顶,取消置顶

第一步:布局

<?xml version="1.0" encoding="utf-8"?>
<com.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.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 -> {
           
        }
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_41620230

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值