在我的Android应用程序中,我想添加从内存中加载图像的功能-代码如下:
LinearLayout linlay = findViewById(R.id.linlay);
Button addImagesButton = findViewById(R.id.addImagesButton);
ActivityResultLauncher<Intent> mChoosePhoto = registerForActivityResult(
new ActivityResultContracts.GetMultipleContents(),
new ActivityResultCallback<List<Uri>>() {
@Override
public void onActivityResult(List<Uri> result) {
res = result;
for (int i = 0; i < result.size(); i++) {
ImageView imageView = new ImageView(SomeActivity.this);
imageView.setPadding(0,0,0,0);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(params);
Glide.with(ReportForLocationActivity.this)
.load(result.get(i))
.into(imageView);
linlay.addView(imageView);
}
}
});
addImagesButton.setOnClickListener(v -> {
mChoosePhoto.launch("image/*");
});
一切正常,但添加到Glide的ImageView元素之间有一个很大的差距-我如何才能使它更小?Screen from emulator
我已经尝试更改边距和填充设置,但它不工作。
1条答案
按热度按时间fhity93d1#
解决了!