Set CardView height programmatically

前端 未结 3 1379
不思量自难忘°
不思量自难忘° 2021-02-19 20:48

I am new to Android dev and I\'m having trouble trying to set the min height of a it.gmariotti.cardslib.library.view.CardView programmatically. I create a new insta

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-19 21:08

    My Solution with margin and it worked perfectly with me
    val resources = context.resources // get resources from context val width: Int = resources.displayMetrics.widthPixels / 3 //get width val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2f, resources.displayMetrics).toInt() //set margin val layoutParams = ViewGroup.MarginLayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT) layoutParams.marginStart = px layoutParams.marginEnd = px cardView.layoutParams = layoutParams

提交回复
热议问题