我正在使用 Glide 进行服务器加载图像。我需要在某些对话框显示之前加载图像。
什么是最好的方法?
编辑:这是我的代码中的示例:
On my dialog class
@Override
protected void onCreate(final Bundle savedInstanceState) {
setContentView(R.layout.dialog_alert);
ButterKnife.bind(this);
int size = mActivity.getResources().getDimensionPixelSize(R.dimen.product_icon);
String productThumbnailUrl = api.getThumbnailUrl(mProduct.getImage(), size, size);
Glide.with(mActivity)
.load(productThumbnailUrl)
.placeholder(R.drawable.icon_default)
.into(mImage);
}
On my activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[...]
AlertProduct dialog = new AlertProduct(this, product);
dialog.show();
}
最佳答案
Loading into targets应该做你想做的。
If you simply want to load a Bitmap so that you can interact with it in some special way other than displaying it directly to the user, maybe to show in a notification, or upload as a profile photo, Glide has you covered.
SimpleTarget provides reasonable default implementations for the much larger Target interface and let's you focus on handling the result of your load.
关于android - Glide - 如何在对话框显示之前加载图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40096259/