【发布时间】:2018-05-07 18:39:13
【问题描述】:
我有以下场景:
我正在动态地将图像 URI 分配给 ImageView,然后将此 ImageView 动态添加到 HorizontalView。
问题是,我没有看到这些图像加载到 ImageView 中,在 HorizontalView 中。
这是我的代码:
<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>
这是我加载图片的代码:
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);
layout.addView(imageView);
}
}
}
这是我的 URI 示例:
content://com.android.providers.media.documents/document/image%3A48
我做错了什么?
【问题讨论】:
-
使用 glide 或 Picasso 加载图片!
标签: java android android-imageview