Android 当元素';s的宽度和高度都被放大了

Android 当元素';s的宽度和高度都被放大了,android,android-recyclerview,kotlin,recyclerview-layout,Android,Android Recyclerview,Kotlin,Recyclerview Layout,我一直在为这个问题挠头。我在recyclerview中有一个recyclerview,它显示了一个网格布局,您可以在其中垂直和水平滚动 我决定放大每件物品的宽度和高度。以前,宽度和高度为:80 x 100 请注意,在设备上运行应用程序时也会发生这种情况。在平板电脑上,它显示所有级别,而在手机上,它只显示级别1-3 外部回收视图布局 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.C

我一直在为这个问题挠头。我在recyclerview中有一个recyclerview,它显示了一个网格布局,您可以在其中垂直和水平滚动

我决定放大每件物品的宽度和高度。以前,宽度和高度为:80 x 100



请注意,在设备上运行应用程序时也会发生这种情况。在平板电脑上,它显示所有级别,而在手机上,它只显示级别1-3

外部回收视图布局

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/swiperefresh"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/toolbar">

            <ScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="always">


                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <include layout="@layout/browsebooksheader_layout"
                        android:id="@+id/bb_header"
                        app:layout_constraintBottom_toTopOf="@+id/guidelinetop"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="parent"/>

                    <android.support.constraint.Guideline
                        android:id="@+id/guidelinetop"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        app:layout_constraintGuide_percent="0.30"/>

                    <Button
                        android:id="@+id/btn_search"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:background="@drawable/search_btn_border"
                        android:padding="8dp"
                        android:text="Search"
                        android:textSize="@dimen/browse_search_textsize"
                        android:textColor="@android:color/darker_gray"
                        app:layout_constraintBottom_toTopOf="@+id/recyclerview_main"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/bb_header" />

                    <ProgressBar
                        android:id="@+id/main_progressbar"
                        style="?android:attr/progressBarStyleSmall"
                        android:layout_marginTop="16dp"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:indeterminateTint="@color/color_grey"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/btn_search"/>


                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerview_main"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        android:background="@color/color_white"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/btn_search"
                        app:layout_constraintBottom_toBottomOf="parent"/>

                </android.support.constraint.ConstraintLayout>
            </ScrollView>



        </android.support.v4.widget.SwipeRefreshLayout>




        <android.support.constraint.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/swiperefresh"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">

            <include layout="@layout/toolbar_layout_wo_learn"/>

        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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="wrap_content">

    <TextView
        android:id="@+id/book_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="Category Title"
        android:textColor="@color/defaultdark_color"
        android:textSize="@dimen/browse_category_textsize"
        android:fontFamily="@font/vagroundedstd_bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:layout_width="@dimen/browse_seeall_imagesize"
        android:layout_height="@dimen/browse_seeall_imagesize"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:id="@+id/see_all_btn"
        android:src="@drawable/seeall"
        app:layout_constraintBottom_toTopOf="@+id/inner_recyclerview"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/inner_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nestedScrollingEnabled="false"
        android:background="@color/color_white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/book_category"/>

    <TextView
        android:id="@+id/h_line"
        android:layout_width="match_parent"
        android:layout_height="0.8dp"
        android:background="@color/color_grey"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:alpha="0.5"
        app:layout_constraintTop_toBottomOf="@id/inner_recyclerview"/>


</android.support.constraint.ConstraintLayout>

内部回收视图布局

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/swiperefresh"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@+id/toolbar">

            <ScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="always">


                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <include layout="@layout/browsebooksheader_layout"
                        android:id="@+id/bb_header"
                        app:layout_constraintBottom_toTopOf="@+id/guidelinetop"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="parent"/>

                    <android.support.constraint.Guideline
                        android:id="@+id/guidelinetop"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        app:layout_constraintGuide_percent="0.30"/>

                    <Button
                        android:id="@+id/btn_search"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:background="@drawable/search_btn_border"
                        android:padding="8dp"
                        android:text="Search"
                        android:textSize="@dimen/browse_search_textsize"
                        android:textColor="@android:color/darker_gray"
                        app:layout_constraintBottom_toTopOf="@+id/recyclerview_main"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/bb_header" />

                    <ProgressBar
                        android:id="@+id/main_progressbar"
                        style="?android:attr/progressBarStyleSmall"
                        android:layout_marginTop="16dp"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:layout_gravity="center"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:indeterminateTint="@color/color_grey"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/btn_search"/>


                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerview_main"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:nestedScrollingEnabled="false"
                        android:background="@color/color_white"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/btn_search"
                        app:layout_constraintBottom_toBottomOf="parent"/>

                </android.support.constraint.ConstraintLayout>
            </ScrollView>



        </android.support.v4.widget.SwipeRefreshLayout>




        <android.support.constraint.ConstraintLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/swiperefresh"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">

            <include layout="@layout/toolbar_layout_wo_learn"/>

        </android.support.constraint.ConstraintLayout>

    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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="wrap_content">

    <TextView
        android:id="@+id/book_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="Category Title"
        android:textColor="@color/defaultdark_color"
        android:textSize="@dimen/browse_category_textsize"
        android:fontFamily="@font/vagroundedstd_bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:layout_width="@dimen/browse_seeall_imagesize"
        android:layout_height="@dimen/browse_seeall_imagesize"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:id="@+id/see_all_btn"
        android:src="@drawable/seeall"
        app:layout_constraintBottom_toTopOf="@+id/inner_recyclerview"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/inner_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:nestedScrollingEnabled="false"
        android:background="@color/color_white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/book_category"/>

    <TextView
        android:id="@+id/h_line"
        android:layout_width="match_parent"
        android:layout_height="0.8dp"
        android:background="@color/color_grey"
        android:gravity="center"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:alpha="0.5"
        app:layout_constraintTop_toBottomOf="@id/inner_recyclerview"/>


</android.support.constraint.ConstraintLayout>

外部适配器

class BrowseBooksAdapter : RecyclerView.Adapter<BrowseBooksAdapter.SimpleViewHolder>() {

    private var sortedList : SortedMap<String, List<ResourcesList>> = emptyMap<String, List<ResourcesList>>().toSortedMap()

    fun setData(sortedList : SortedMap<String, List<ResourcesList>>) {
        if (this.sortedList != sortedList) {
            this.sortedList = sortedList
            notifyDataSetChanged()
        }
    }

    override fun getItemCount(): Int {
        return sortedList.count()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.browsebooks_layout, parent, false)
        return SimpleViewHolder(view)
    }

    override fun onBindViewHolder(holder: SimpleViewHolder, position: Int) {

        val dataList = ArrayList(sortedList.values)[position]
        holder.category_text.text = ArrayList(sortedList.keys)[position]
        holder.booksByCategory = dataList
        holder.horizontalAdapter.setData(dataList)
    }

    class SimpleViewHolder(v: View, var booksByCategory : List<ResourcesList>? = null) : RecyclerView.ViewHolder(v) {
        var recyclerView : RecyclerView = v.findViewById(R.id.inner_recyclerview)
        var category_text : TextView = v.findViewById(R.id.book_category)
        var fragmentCallback: FragmentCallback? = null
        val horizontalAdapter: BooksByCategoryAdapter


        init {
            recyclerView.layoutManager = object : LinearLayoutManager(v.context, LinearLayoutManager.HORIZONTAL, false) {
                override fun canScrollHorizontally(): Boolean {
                    return true
                }

                override fun canScrollVertically(): Boolean {
                    return false
                }
            }
            horizontalAdapter = BooksByCategoryAdapter()
            recyclerView.adapter = horizontalAdapter
            fragmentCallback = v.context as FragmentCallback
            var mLastClickTime : Long = 0


            v.see_all_btn.setOnClickListener {
                val category = v.book_category.text.toString()

                // double-clicking prevention, using threshold of 1000 ms
                if (!(SystemClock.elapsedRealtime() - mLastClickTime < 1000)){
                    mLastClickTime = SystemClock.elapsedRealtime()

                    if(fragmentCallback != null){
                        fragmentCallback!!.callBackSeeAllFragment(booksByCategory!!, category)
                    }
                }

            }
        }

    }

}
class BooksByCategoryAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var booksByCategory: List<ResourcesList> = emptyList()

fun setData(data: List<ResourcesList>) {
    if (this.booksByCategory != data) {
        this.booksByCategory = data
        notifyDataSetChanged()
    }
}

override fun getItemCount(): Int {
    return booksByCategory.size
}


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    val layoutInflater = LayoutInflater.from(parent.context)
    val cellForRow = layoutInflater.inflate(R.layout.bookcontainer_layout, parent, false)
    return CustomVH(cellForRow)
}

override fun onBindViewHolder(rawHolder: RecyclerView.ViewHolder, position: Int) {
    val holder = rawHolder as CustomVH
    val booksProcessModel = BooksProcessModel()
    booksProcessModel.setItem(booksByCategory[position])
    holder.booksByCategory = booksByCategory[position]
    Picasso.get().load(booksByCategory[position].coverURI).into(holder.inner_bookcover)


}

private inner class CustomVH(v: View, var booksByCategory : ResourcesList? = null): RecyclerView.ViewHolder(v) {

    var inner_bookcover : ImageView = v.findViewById(R.id.inner_bookcover)
    var fragmentCallback: FragmentCallback? = null
    var ctx : Context = v.context
    var mLastClickTime : Long = 0

    init {
        fragmentCallback = ctx as FragmentCallback

        v.setOnClickListener {

            // double-clicking prevention, using threshold of 1000 ms
            if (!(SystemClock.elapsedRealtime() - mLastClickTime < 1000)){
                mLastClickTime = SystemClock.elapsedRealtime()

                if(fragmentCallback != null){
                    fragmentCallback!!.callBackDownloadBookFragment(booksByCategory!!)
                }
            }

        }

    }
}

class BooksProcessModel {

    private var processBooks : ResourcesList? = null

    fun setItem(books: ResourcesList) {
        this.processBooks = books
    }

    fun setVisibility(ctx: Context) : Int {

        val sp = PreferenceManager.getDefaultSharedPreferences(ctx)
        val page = sp.getString(processBooks!!.id.toString(), "")
        if (page != "") {
            return View.VISIBLE
        }
        return View.INVISIBLE
    }

}
class-BrowseBooksAdapter:RecyclerView.Adapter(){
私有变量sortedList:SortedMap=emptyMap().toSortedMap()
趣味设置数据(分类列表:分类地图){
如果(this.sortedList!=sortedList){
this.sortedList=sortedList
notifyDataSetChanged()
}
}
重写getItemCount():Int{
返回sortedList.count()
}
override fun onCreateViewHolder(父级:ViewGroup,viewType:Int):SimpleViewHolder{
val view=LayoutInflater.from(parent.context).充气(R.layout.browsebooks_布局,parent,false)
返回SimpleView文件夹(视图)
}
覆盖onBindViewHolder(holder:SimpleView文件夹,位置:Int){
val dataList=ArrayList(sortedList.values)[位置]
holder.category_text.text=ArrayList(sortedList.keys)[位置]
holder.booksByCategory=数据列表
holder.horizontalAdapter.setData(数据列表)
}
类SimpleViewHolder(v:View,var booksByCategory:List?=null):RecycleView.ViewHolder(v){
var recyclerView:recyclerView=v.findViewById(R.id.inner\u recyclerView)
变量类别\文本:TextView=v.findViewById(R.id.book\类别)
var fragmentCallback:fragmentCallback?=null
val horizontalAdapter:BooksByCategoryAdapter
初始化{
recyclerView.layoutManager=对象:LinearLayoutManager(v.context,LinearLayoutManager.HORIZONTAL,false){
水平覆盖():布尔值{
返回真值
}
override fun canscrollvertical():布尔值{
返回错误
}
}
horizontalAdapter=BooksByCategoryAdapter()
recyclerView.adapter=水平适配器
fragmentCallback=v.context作为fragmentCallback
var mLastClickTime:Long=0
v、 请参阅\u all\u btn.setOnClickListener{
val category=v.book_category.text.toString()
//双击预防,使用1000毫秒的阈值
如果(!(SystemClock.elapsedRealtime()-mLastClickTime<1000)){
mLastClickTime=SystemClock.elapsedRealtime()
if(fragmentCallback!=null){
fragmentCallback!!.callBackSeeAllFragment(booksByCategory!!,category)
}
}
}
}
}
}
内部适配器

class BrowseBooksAdapter : RecyclerView.Adapter<BrowseBooksAdapter.SimpleViewHolder>() {

    private var sortedList : SortedMap<String, List<ResourcesList>> = emptyMap<String, List<ResourcesList>>().toSortedMap()

    fun setData(sortedList : SortedMap<String, List<ResourcesList>>) {
        if (this.sortedList != sortedList) {
            this.sortedList = sortedList
            notifyDataSetChanged()
        }
    }

    override fun getItemCount(): Int {
        return sortedList.count()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SimpleViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.browsebooks_layout, parent, false)
        return SimpleViewHolder(view)
    }

    override fun onBindViewHolder(holder: SimpleViewHolder, position: Int) {

        val dataList = ArrayList(sortedList.values)[position]
        holder.category_text.text = ArrayList(sortedList.keys)[position]
        holder.booksByCategory = dataList
        holder.horizontalAdapter.setData(dataList)
    }

    class SimpleViewHolder(v: View, var booksByCategory : List<ResourcesList>? = null) : RecyclerView.ViewHolder(v) {
        var recyclerView : RecyclerView = v.findViewById(R.id.inner_recyclerview)
        var category_text : TextView = v.findViewById(R.id.book_category)
        var fragmentCallback: FragmentCallback? = null
        val horizontalAdapter: BooksByCategoryAdapter


        init {
            recyclerView.layoutManager = object : LinearLayoutManager(v.context, LinearLayoutManager.HORIZONTAL, false) {
                override fun canScrollHorizontally(): Boolean {
                    return true
                }

                override fun canScrollVertically(): Boolean {
                    return false
                }
            }
            horizontalAdapter = BooksByCategoryAdapter()
            recyclerView.adapter = horizontalAdapter
            fragmentCallback = v.context as FragmentCallback
            var mLastClickTime : Long = 0


            v.see_all_btn.setOnClickListener {
                val category = v.book_category.text.toString()

                // double-clicking prevention, using threshold of 1000 ms
                if (!(SystemClock.elapsedRealtime() - mLastClickTime < 1000)){
                    mLastClickTime = SystemClock.elapsedRealtime()

                    if(fragmentCallback != null){
                        fragmentCallback!!.callBackSeeAllFragment(booksByCategory!!, category)
                    }
                }

            }
        }

    }

}
class BooksByCategoryAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var booksByCategory: List<ResourcesList> = emptyList()

fun setData(data: List<ResourcesList>) {
    if (this.booksByCategory != data) {
        this.booksByCategory = data
        notifyDataSetChanged()
    }
}

override fun getItemCount(): Int {
    return booksByCategory.size
}


override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    val layoutInflater = LayoutInflater.from(parent.context)
    val cellForRow = layoutInflater.inflate(R.layout.bookcontainer_layout, parent, false)
    return CustomVH(cellForRow)
}

override fun onBindViewHolder(rawHolder: RecyclerView.ViewHolder, position: Int) {
    val holder = rawHolder as CustomVH
    val booksProcessModel = BooksProcessModel()
    booksProcessModel.setItem(booksByCategory[position])
    holder.booksByCategory = booksByCategory[position]
    Picasso.get().load(booksByCategory[position].coverURI).into(holder.inner_bookcover)


}

private inner class CustomVH(v: View, var booksByCategory : ResourcesList? = null): RecyclerView.ViewHolder(v) {

    var inner_bookcover : ImageView = v.findViewById(R.id.inner_bookcover)
    var fragmentCallback: FragmentCallback? = null
    var ctx : Context = v.context
    var mLastClickTime : Long = 0

    init {
        fragmentCallback = ctx as FragmentCallback

        v.setOnClickListener {

            // double-clicking prevention, using threshold of 1000 ms
            if (!(SystemClock.elapsedRealtime() - mLastClickTime < 1000)){
                mLastClickTime = SystemClock.elapsedRealtime()

                if(fragmentCallback != null){
                    fragmentCallback!!.callBackDownloadBookFragment(booksByCategory!!)
                }
            }

        }

    }
}

class BooksProcessModel {

    private var processBooks : ResourcesList? = null

    fun setItem(books: ResourcesList) {
        this.processBooks = books
    }

    fun setVisibility(ctx: Context) : Int {

        val sp = PreferenceManager.getDefaultSharedPreferences(ctx)
        val page = sp.getString(processBooks!!.id.toString(), "")
        if (page != "") {
            return View.VISIBLE
        }
        return View.INVISIBLE
    }

}
classbooksbycategoryadapter:RecyclerView.Adapter(){
private-var booksByCategory:List=emptyList()
fun setData(数据:列表){
if(this.booksByCategory!=数据){
this.booksByCategory=数据
notifyDataSetChanged()
}
}
重写getItemCount():Int{
返回booksByCategory.size
}
override fun onCreateViewHolder(父级:ViewGroup,viewType:Int):RecyclerView.ViewHolder{
val layoutInflater=layoutInflater.from(parent.context)
val cellForRow=layoutInflater.flate(R.layout.bookcontainer\u布局,父级,false)
返回客户VH(cellForRow)
}
覆盖BindViewHolder(rawHolder:RecyclerView.ViewHolder,位置:Int){
val holder=作为客户VH的rawHolder
val booksProcessModel=booksProcessModel()
booksProcessModel.setItem(booksByCategory[位置])
holder.booksByCategory=booksByCategory[位置]
Picasso.get().load(booksByCategory[position].coverURI).into(holder.inner_bookcover)
}
私有内部类CustomVH(v:View,var booksByCategory:ResourcesList?=null):RecyclerView.ViewHolder(v){
var内封面:ImageView=v.findViewById(R.id.inner封面)
var fragmentCallback:fragmentCallback?=null
var ctx:Context=v.Context
var mLastClickTime:Long=0
初始化{
fragmentCallback=ctx作为fragmentCallback
v、 setOnClickListener{
//双击预防,使用1000毫秒的阈值
如果(!(SystemClock.elapsedRealtime()-mLastClickTime<1000)){
mLastClickTime=SystemClock.elapsedRealtime()
if(fragmentCallback!=null){
fragmentCallback!!.callBackDownloadBookFragment(booksByCategory!!)
}
}
}
}
}
类处理模型{
私有变量processBooks:ResourcesList?=null
趣味设置项(书籍:资源列表){
this.processBooks=书籍
}
fun setVisibility(ctx:Context):Int{
val sp=PreferenceManager.GetDefaultSharedReferences(ctx)
val page=sp.getString(processBooks!!.id.toString(),“”)
如果(第页!=“”){
返回视图。可见
}
返回视图。不可见
}
}

}

您需要将外部回收器视图的
布局高度更改为
包装内容
无需担心,解决它。我应该使用NestedScrollView而不是ScrollView。丢失的物品仍在那里。只是我无法滚动嵌套的recyclerview。

在我的例子中,它是b