为什么只有第一行显示使用Recyclerview gridlayoutmanager

时间:2017-08-03 04:42:01

标签: android gridview android-recyclerview kotlin

适配器呼叫:

adherenceDetails.hasFixedSize()
                    adherenceDetails.layoutManager= GridLayoutManager(this@PatientPlanStatus,3)
                    adherenceDetails.adapter= PatientPlanDetails(this@PatientPlanStatus, patientPlanAdherenceData.data?.get(0)?.adherence!!)

适配器:

class PatientPlanDetails(var mcontext: Context, var patientDatas:ArrayList<AdherencePoJo>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {

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

    val TAG="PatientPlanDetails"


    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {

        val v = LayoutInflater.from(mcontext).inflate(R.layout.patient_plan_adherence, parent, false)
        return Item(v)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder?, position: Int) {

        //Log.i(TAG,"On Bind")
        (holder as Item).bindData(patientDatas.get(position),mcontext)


    }

    class Item(itemView: View) : RecyclerView.ViewHolder(itemView) {


        fun bindData(patienData: AdherencePoJo, context: Context) {

            val TAG="PatientPlanDetails"

        }

    }


}

getItemCount()返回正确的大小。但只有第一行显示。请查看图片enter image description here 卡片具有实际高度,但其中的项目不可见。 我也没有登录注销。

2 个答案:

答案 0 :(得分:1)

patient_plan_adherence 布局高度设为wrap_content

答案 1 :(得分:0)

在您的RecyclerView中尝试使用此属性:

app:layout_behavior =“ @ string / appbar_scrolling_view_behavior”

enter image description here