Glide ImageView元素之间的间隙Android Studio

omqzjyyz  于 2023-03-27  发布在  Android
关注(0)|答案(1)|浏览(132)

在我的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
我已经尝试更改边距和填充设置,但它不工作。

fhity93d

fhity93d1#

解决了!

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(
                                    ViewGroup.LayoutParams.WRAP_CONTENT,
                                    ViewGroup.LayoutParams.WRAP_CONTENT);
                            imageView.setLayoutParams(params);
                            imageView.setAdjustViewBounds(true);
                            Glide.with(ReportForLocationActivity.this)
                                    .load(result.get(i))
                                    .into(imageView);

                            linlay.addView(imageView);
                        }
                    }
                });

addImagesButton.setOnClickListener(v -> {
    mChoosePhoto.launch("image/*");
});

相关问题