我正在尝试从服务器获取10张图像,并以编程方式创建壁画draweeViews并将其置于可滚动视图中。

到目前为止我尝试过的

 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);
    }
}


这种方法适用于毕加索和滑翔,但我无法使其适用于壁画。有人可以帮我吗?

顺便说一下,服务器已启动并正在运行,因此您可以根据需要对其进行测试

最佳答案

如文档所述:

SimpleDraweeView不支持layout_width或layout_height属性的wrap_content。

因此,我修改了linearLayout参数,并为视图设置了最小宽度。现在它就像一个魅力

 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);


    }
}

10-08 18:27