【发布时间】:2020-04-01 22:19:15
【问题描述】:
我有一个嵌套在线性布局中的 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>
我还有一个 ImageView 的扩展函数,它使用 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 日志中,我可以看到加载到其中的每个模型都有传递给 glide 的 URI,但是图像和进度可绘制对象都没有出现在大约一半的视图中。父母只是折叠和缩小每个 ViewHolder。我的实现有什么问题?
【问题讨论】:
标签: android xml android-glide