RecyclerView添加下划线

RecyclerView添加下划线

最近写一个项目,要给RecyclerView添加下滑线,由于本人比较菜,所以去度娘上搜了一波,发现大神们的代码量真的好长(主要是我太懒),然后就想能不能在xml文件里做一些手脚,结果发现还真行。
第一步:在recyclerview的布局文件里加一个view:


<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
        android:paddingLeft="18dp">

        <TextView
            android:id="@+id/notes_content_part"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textColor="#000"/>

        <TextView
            android:id="@+id/notes_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:textSize="14sp"/>

    </LinearLayout>

    <View
        android:id="@+id/updownline"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#dfdfdf"
        android:layout_marginLeft="18dp"/>

这个view加在顶部或者底部都可以:

第二步,在适配器中去掉最底下的view:

static class ViewHolder extends RecyclerView.ViewHolder {

        TextView notes_content_part;
        TextView notes_time;
        View updownline;

        public ViewHolder(View itemView) {
            super(itemView);
            notes_content_part = itemView.findViewById(R.id.notes_content_part);
            notes_time = itemView.findViewById(R.id.notes_time);
            updownline = itemView.findViewById(R.id.updownline);//获取view布局
        }
    }
@Override
    public void onBindViewHolder(NotesAdapter.ViewHolder holder, int position) {
        Notes notes = list.get(position);
        holder.notes_content_part.setText(notes.getNotes_content_part());
        holder.notes_time.setText(notes.getNotes_time());
        //当当前的item为最后一个时隐藏view
        if(position == list.size()-1) {
            holder.updownline.setVisibility(View.GONE);
        }
    }

Ok这样你就可以实现简单的recyclerview分割线了(虽然比较lower)。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值