Facebook Fresco using wrap_content

前端 未结 5 714
日久生厌
日久生厌 2020-12-05 03:07

I got a bunch of drawables that I want to load using fresco, I want to use wrap_content size for those images, how can I do it in xml with fresco? Or if xml is

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 03:45

    In Kotlin you can try something like this :

           val listener = object : BaseControllerListener() {
            override fun onFinalImageSet(id: String?, imageInfo: ImageInfo?, animatable: Animatable?) {
                super.onFinalImageSet(id, imageInfo, animatable)
                itemView.draweeGif.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
                itemView.draweeGif.aspectRatio = (imageInfo?.width?.toFloat() ?: 0.toFloat()) / (imageInfo?.height?.toFloat() ?: 0.toFloat())
            }
        }
    
        val controller = Fresco.newDraweeControllerBuilder()
            .setUri(uriGif)
            .setControllerListener(listener)
            .setAutoPlayAnimations(true)
            .build()
        itemView.draweeGif.controller = controller
    

    For me it was a solution in my RecyclerView because I was looking to set the layoutParams directly in my ViewHolder.

提交回复
热议问题