<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                在[上篇博客](https://futurestud.io/blog/glide-module-example-optimizing-by-loading-images-in-custom-sizes)中,你已經看到了如何聲明和配置一個 Glide module,它在請求中增加了圖像大小。這是非常有用的優化。然而,重要的是要知道,聲明 Glide module 總是主動的。默認情況下,你不能動態的打開或者關閉它們。 在這篇博客中,你會學到如何去注冊對當個請求去一個自定義的 model 加載器。 **自定義圖像大小?** 提示:如果你還沒讀過我們[之前的博客](https://futurestud.io/blog/glide-module-example-optimizing-by-loading-images-in-custom-sizes),現在去讀一下。否則,下面這部分看起來很困難。 作為一個簡短的回顧:通常 Glide 的請求是和 `GlideUrl` 類來使用的。上周我們已經向你展示了如何創建一個新的接口,來考慮增加寬度和高度。 ~~~ public interface CustomImageSizeModel { String requestCustomSizeUrl(int width, int height); } ~~~ 我們創建了一個實現,它及案例額傳遞了圖像的 URL 加上尺寸提交給了工作服務器。 ~~~ public static class CustomImageSizeModelFutureStudio implements CustomImageSizeModel { String baseImageUrl; public CustomImageSizeModelFutureStudio(String baseImageUrl) { this.baseImageUrl = baseImageUrl; } @Override public String requestCustomSizeUrl(int width, int height) { return baseImageUrl + "?w=" + width + "&h=" + height; } } ~~~ 最后,這并不是最重要的,我們必須創建一個 `CustomImageSizeUrlLoader`,它傳了寬度和高度給了我們的 model 實現: ~~~ public static class CustomImageSizeUrlLoader extends BaseGlideUrlLoader<CustomImageSizeModel> { public CustomImageSizeUrlLoader(Context context) { super( context ); } @Override protected String getUrl(CustomImageSizeModel model, int width, int height) { return model.requestCustomSizeUrl( width, height ); } } ~~~ **Model Loader 和 .using() 的動態使用?** 目前我們已經聲明了 Glide module。Glide 會把它用在每一個請求。如果你不想這樣,從 `AndroidManifest.xml `中刪除你的 Glide module。我們可以這么做是因為 Glide 提供了 `.using()` 方法去為單個的請求指定一個 model。 ~~~ String baseImageUrl = "https://futurestud.io/images/example.png"; CustomImageSizeModel customImageRequest = new CustomImageSizeModelFutureStudio( baseImageUrl ); Glide .with( context ) .using( new CustomImageSizeUrlLoader( context ) ) .load( customImageRequest ) .into( imageView1 ); ~~~ 正如你看到的,我們正在創建一個 `CustomImageSizeModelFutureStudio` 對象來為我們的圖像按照指定的大小加載。因為沒有在 Glide module 中聲明 `CustomImageSizeModel` 接口,我們必須指明這行代碼 `.using(new CustomImageSizeUrlLoader(context))`。Glide 現在會只為這個請求用這個 model。對于其他的請求,即使它們有 `CustomImageSizeModel` 接口,也不會受影響。 **Outlook**? 這篇博客中,你已經學到了如何 為指定的請求去指定 model。如果你不想要在 `AndroidManifest` 中使用 Glide module ,這是一個簡單的選擇。 有了這個博客文章,我們就完成了深入進入 Glide module 以及它們的用途。下周,我們會將這個系列包裹起來。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看