1

I am trying to get 10 images from the server and programmatically create fresco draweeViews and put them into scrollable view.

What I have tried so far

 private LinearLayout linearLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    linearLayout = findViewById(R.id.linearLayout);
    Fresco.initialize(this);
    getImages("1");

} 
public void getImages(String size) {

    for (int i = 1; i <= 10; i++) {

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.setMargins(0, 0, 0, 0);
        SimpleDraweeView image = new SimpleDraweeView(this);
        image.setLayoutParams(lp);
        // Adds the view to the layout
        linearLayout.addView(image);

        Uri uri = Uri.parse("https://desolate-beach-17272.herokuapp.com/downloadFile/" + size + "mb" + i + ".jpg");
        image.setImageURI(uri);
    }
}

This approached worked with picasso and glide but I couldn't make it work with fresco. Can somone help me with that?

By the way, the server is up and running so you can test it if you want

wolf
  • 399
  • 1
  • 6
  • 19

1 Answers1

2

As the documentation states :

SimpleDraweeView does not support wrap_content for layout_width or layout_height attributes.

So I modified linearLayout parameters and I set min-width for the view. Now it works like a charm

 public void getImages(String size) {

    for (int i = 1; i <= 10; i++) {

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        SimpleDraweeView draweeView = new SimpleDraweeView(this);
        draweeView.setLayoutParams(lp);
        draweeView.setMinimumWidth(150);
        draweeView.setMinimumHeight(1500);
        // Adds the view to the layout
        linearLayout.addView(draweeView);

        Uri uri = Uri.parse("https://desolate-beach-17272.herokuapp.com/downloadFile/" + size + "mb" + i + ".jpg");

        draweeView.setImageURI(uri);


    }
}
wolf
  • 399
  • 1
  • 6
  • 19