Here是我之前动态设置ImageView
的尝试。有人建议我使用图像库,所以我决定使用Picasso:
这是我的权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" tools:ignore="ProtectedPermissions" />
这是图片URI:
content://com.android.providers.media.documents/document/image%3A48
资源代码:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/imageDisplayer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
我如何将图像加载到ImageView中:
public void LoadImages(ArrayList<PhotoPath> photos){
LinearLayout layout = (LinearLayout)findViewById(R.id.imageDisplayer);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (photos != null) {
for (PhotoPath photo : photos) {
Uri photoUri = Uri.parse(photo.getPhotoPath());
params.setMargins(10, 10, 10, 10);
params.gravity = Gravity.NO_GRAVITY;
ImageView imageView = new ImageView(this);
//imageView.setImageURI(photoUri);
imageView.setLayoutParams(params);
Picasso.get().load(photoUri)
.resize(100, 100)
.error(R.mipmap.ic_account)
.into(imageView);
layout.addView(imageView);
}
}
}
问题是,error
mipmap正在显示,即使photoUri
不为空。
我的Uri
是否有问题?