Android recycleview和item的关系

本文介绍了在Android应用中使用RecyclerView进行嵌套Item布局的方法。通过具体的XML代码示例,展示了如何设置RecyclerView及其内部Item的布局参数,实现精确的间距控制,并避免因布局设置不当导致的视觉效果问题。

recycleview里面嵌套着item,在这个布局里面就单纯的设置recycleview的位置
在这里插入图片描述
RecyclerView的代码

        <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView2"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                app:layout_constraintLeft_toRightOf="@+id/barr_name"
                app:layout_constraintTop_toBottomOf="@+id/tv_person_movie"
                app:layout_constraintBottom_toTopOf="@+id/tv_mydynamic" />

下面是item的代码,在里面设置的android:layout_marginLeft=“8dp”
android:layout_marginRight=“8dp”
android:layout_marginTop=“16dp”,这些都是相对于recycleview来说的,相对recycleview的距离
在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tool="http://schemas.android.com/tools"
    android:layout_width="150dp"
    android:layout_height="200dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="16dp"//这句代码不能要,加了的话,item里面的图片就往下移动了,如果你用glide做圆角将会发现,下面两个角都不是圆的。反正就是一个框,框里面就是item了,如果是水平滑动框,如果你又调了item上下位置,那这个item就有可能被框挡住。可以调三个布局的距离,第一个是框的上下左右距离,第二个就是item的相对框的上下左右距离,还有一个就是item里面的imageview相对item的上下左右距离
    android:orientation="vertical">

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/iv_person_vedio"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        tool:src="#000000" />

    <ImageButton
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@mipmap/icon_bofang"
        android:layout_alignTop="@+id/iv_person_vedio"
        android:layout_alignStart="@+id/iv_person_vedio"
        android:layout_marginStart="60dp"
        android:layout_marginTop="80dp"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:background="@color/transparent"
        />

</RelativeLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值