当前位置:优学网  >  在线题库

RecyclerView中的项目小于要求

发表时间:2022-07-13 01:06:33 阅读:61

在设计上看起来还可以,但当我运行应用程序时,它看起来像这样1

回收查看项目:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="230dp"
    android:layout_height="100dp"
    app:cardCornerRadius="15dp"
    app:cardBackgroundColor="@color/card_color">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/sizeTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/pt_sans"
            android:text="TextView"
            android:textColor="@color/black"
            android:textSize="15sp"
            android:layout_marginTop="11dp"
            app:layout_constraintStart_toStartOf="@+id/nameTextView"
            app:layout_constraintTop_toBottomOf="@+id/nameTextView" />

        <TextView
            android:id="@+id/nameTextView"
            android:layout_width="wrap_content"
            android:maxWidth="150dp"
            android:layout_height="25dp"
            android:layout_marginStart="25dp"
            android:layout_marginTop="22dp"
            android:text="Breaking Bad"
            android:textColor="@color/black"
            android:fontFamily="@font/pt_sans"
            android:textSize="20sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginTop="6dp"
            app:layout_constraintBottom_toBottomOf="@+id/nameTextView"
            app:layout_constraintStart_toEndOf="@+id/nameTextView"
            app:layout_constraintTop_toTopOf="@+id/nameTextView"
            app:srcCompat="@drawable/little_folder_icon" />
    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

适配器:

class HomePageFoldersAdapter() : RecyclerView.Adapter<HomePageFoldersAdapter.FolderHolder>() {

    var list = emptyList<Folder>()
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FolderHolder {
        val inflater = LayoutInflater.from(parent.context)
        val binding = FolderHomeCardBinding.inflate(inflater)
        return FolderHolder(binding)
    }

    override fun onBindViewHolder(holder: FolderHolder, position: Int) {
        val folder = list[position]
        with(holder.binding) {
            val context = root.context
            nameTextView.text = folder.name
            sizeTextView.text = context.getString(R.string.modules_count, folder.modulesIds.size)
        }
    }

    override fun getItemCount() = list.size

    class FolderHolder(val binding: FolderHomeCardBinding) : RecyclerView.ViewHolder(binding.root)

}

我不知道还能写什么(看起来你的帖子大多是代码,请添加更多细节.)

这是四月里一个明亮寒冷的日子,钟敲了十三下.温斯顿·史密斯(Winston Smith)用鼻子捂着下巴,试图避开恶劣的风,他很快地从胜利大厦的玻璃门滑了出去,但速度还不足以阻止一团沙尘随他一起进入.

走廊里有煮卷心菜和旧抹布垫的味道.在它的一端,墙上钉着一张彩色海报,太大了,不宜在室内展示.它只是描绘了一张一米多宽的大脸:一个大约45岁的男人的脸,留着浓密的黑胡子,五官英俊.温斯顿向楼梯走去.尝试电梯是没有用的.即使在最好的时候,它也很少工作,目前电流在白天被切断.这是为仇恨周做准备的经济活动的一部分.公寓有七层楼高,39岁的温斯顿右脚踝上方有静脉曲张性溃疡,他走得很慢,在路上休息了好几次.在电梯井对面的每一层楼梯上,海报都有一张巨大的脸从墙上凝视着.这是一张如此做作的照片,当你移动时,眼睛会跟着你."老大哥"在看你,下面的标题写着.

🎖️ 优质答案
相关问题