滑行无法将图像加载到ImagView中

问题描述 投票:0回答:1

我有一个嵌套在线性布局中的ImageView:

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginRight="20dp"
        android:background="@drawable/tile_background"
        android:elevation="2dp"
        android:orientation="vertical">


        <ImageView
            android:id="@+id/coverTile"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/image_frame_community"
            android:imageUrl="@{sponsorship.coverTileUri}">

        </ImageView>


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center_vertical"
            android:layout_marginTop="-7dp"
            android:layout_marginBottom="5dp"
            android:background="@color/white"
            android:paddingLeft="20dp">

            <TextView
                android:id="@+id/postActionText"
                style="@style/ActionFont"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                tools:text="@string/watch_respond">

            </TextView>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:src="@drawable/ic_chevron_right_black_36dp">

            </ImageView>


        </RelativeLayout>


    </LinearLayout>

我还有一个采访扩展功能,它使用Glide并通过数据绑定绑定到版面:

    fun ImageView.loadImage(uri: String, progressDrawable: CircularProgressDrawable) {

    val options = RequestOptions().placeholder(progressDrawable).error(R.drawable.ic_launcher_background)

    this.clipToOutline = true

    Glide.with(context)
        .setDefaultRequestOptions(options)
        .load(uri).into(this)


}

@BindingAdapter("android:imageUrl")
fun loadImage(view: ImageView, url: String) {
    view.loadImage(url, getProgressDrawable(view.context))
}




fun getProgressDrawable(context: Context): CircularProgressDrawable {
    return CircularProgressDrawable(context).apply {
        strokeWidth = 10f
        centerRadius = 50f
        start()
    }

在我的RecyclerView日志中,我可以看到加载到其中的每个模型都有传递的URI。滑行,但是图像和进度可绘制项都没有出现在大约一半的视图中。父母只是在缩小和缩小每个ViewHolder。我的实现有什么问题?

android xml android-glide
1个回答
0
投票

要使绑定适配器正常工作,必须使用静态函数,在kotlin的情况下,它将是一个伴随对象,并添加@JvmStatic,如下所示:

companion object{
@BindingAdapter("android:imageUrl")
@JvmStatic
    fun loadImages(view: ImageView, url: String){
        view.loadImage(url, getProgressDrawable(view.context))
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.