Java 动态设置ImageView.setImageUri不显示图像

Java 动态设置ImageView.setImageUri不显示图像,java,android,android-imageview,Java,Android,Android Imageview,我有以下情况: 我将动态地将图像URI分配给ImageView,然后将此ImageView动态地添加到HorizontalView 问题是,我没有看到这些图像加载到ImageView中,在HorizontalView中 这是我的密码: <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="100dp">

我有以下情况:

我将动态地将图像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);
            }
        }
    }
公共void加载图像(ArrayList照片){
LinearLayout布局=(LinearLayout)findViewById(R.id.imageDisplayer);
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
如果(照片!=null){
用于(光路照片:照片){
Uri photoUri=Uri.parse(photo.getPhotoPath());
参数设置边距(10,10,10,10);
参数重力=重力。无重力;
ImageView ImageView=新的ImageView(此);
setImageURI(photoUri);
imageView.setLayoutParams(参数);
layout.addView(imageView);
}
}
}
下面是我的URI的一个示例:

content://com.android.providers.media.documents/document/image%3A48

我做错了什么?

setImageURI(Uri Uri)
在UI线程上读取和解码位图。因此,这可能会导致主线程中的延迟,因为图像大小可能会变化,并且加载需要时间。由于它位于主线程上,因此可能会导致不完整性问题

从文件中

setImageURI(Uri Uri)
在UI线程上读取和解码位图,这可能会导致延迟中断。如果这是一个问题,考虑使用SETIMAGEDRAWRABLE(可绘制)或SeTimeAdBMAP(Android,图形,位图)和BitmapFactory代替。
有效的解决方案是使用优化的ImageLoader库。您可以使用它,因为它被广泛推荐

使用glide或毕加索加载图像。!