Skip to content

Latest commit

 

History

History
72 lines (53 loc) · 1.8 KB

image_options_zh.md

File metadata and controls

72 lines (53 loc) · 1.8 KB

ImageOptions

翻译:English

ImageOptions 用来批量定义图片请求配置,支持 ImageRequest 全部图片相关属性

目前可以在三个地方使用 ImageOptions

最终在构建 ImageRequest 时将以 ImageRequest.Builder > View > ImageRequest .Builder.defaultOptions > Sketch.globalImageOptions 的顺序构建

示例

Global:

class MyApplication : Application(), SketchFactory {

    override fun createSketch(): Sketch {
        return Sketch.Builder(this).apply {
          globalImageOptions(ImageOptions {
            placeholer(R.drawable.placeholder)
            error(R.drawable.error)
            // more ...
          })
        }.build()
    }
}

View:

sketchImageView.displayImageOptions = ImageOptions {
    placeholer(R.drawable.placeholder)
    // more ...
}

// 在现有 ImageOptions 基础上更新
sketchImageView.updateDisplayImageOptions {
    error(R.drawable.error)
}

ImageRequest:

DisplayRequest(context, "http://sample.com/sample.jpeg") {
    merge(ImageOptions {
        // ...
    })
    default(ImageOptions {
        // ...
    })
}