Add imageViews dynamically on Android

99封情书 提交于 2019-12-06 09:20:38

You need add LayoutParams to your ImageViews, like this:

       for(int i=0; i< imgList.size(); i++) {
            ImageView imgView = new ImageView(NoticeContent.this);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(200, 200);
            imgView.setLayoutParams(lp);
            Glide.with(NoticeContent.this)
                 .load(imgList.get(i))
                 .override(200,200)
                 .into(imgView);
            linearLayout.addView(imgView);
        }

Try this

 for(int i=0; i< imgList.size(); i++) {
        ImageView imgView = new ImageView(this);
        imgView.setId(i++);
        Glide.with(this).load(imgList.get(i)).override(200,200).into((ImageView)findViewById(i++))
        linearLayout.addView(imgView);
    }

or

for (UserListData userListData : userListDatas){
        Glide.with(getActivity())
                .load(userListData.getAvatar())
                .asBitmap()
                .fitCenter()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {

                        ImageView image = new ImageView(getActivity());
                        image.setImageBitmap(resource);
                        layout.add(image);
                    }
                });

    }

I haven't tested these ones int this way but it should work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!