使用默认的Android图像查看器显示图片 [英] Using the default android image Viewer to show pics

查看:1163
本文介绍了使用默认的Android图像查看器显示图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用默认的android image Viewer(例如new Intent(Intent.ACTION_VIEW)等)打开图像.

I know that I can open an image using the default android image Viewer, for example with new Intent(Intent.ACTION_VIEW) etc.

如果我打开图像,然后向左/向右滑动,则会看到其他图像保存在设备上.

If I open the image and then I swipe left/right I'll see the other images saved on the device.

例如,如果我打开一张whatsapp图片,向左/向右滑动,我会看到所有其他保存在whatsapp文件夹中的图片.

For example, if I open one of whatsapp images, swiping left/right I'll see all other images saved inside whatsapp folder.

是否有一种方法可以将默认的Android图像查看器传递给uri的List/Array,以防止用户向左/向右滑动并查看设备上的所有图像?

Is there a way to pass the default android image Viewer a List/Array of uri, in order to prevent users from swiping left/right and see all the images on the device?

我希望用户向左/向右滑动,只看到我允许他看到的图像.

I want the user to swipe left/right and see only images I allow him to see.

提前谢谢

推荐答案

尝试此操作,您可以使用

try this you can use android.support.v4.view.ViewPager

布局管理器,允许用户在数据页面之间左右翻转.您提供了PagerAdapter的实现以生成视图显示的页面.

Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows.

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

</android.support.v4.view.ViewPager>

演示代码

ViewPager viewPager;
ArrayList<String> imageArray;
imageArray = new ArrayList<>();
viewPager = findViewById(R.id.cspl_viewPager);
imageArray.add(R.drawable.bg);
imageArray.add(R.drawable.bg);
imageArray.add(R.drawable.bg);
imageArray.add(R.drawable.bg);
imageArray.add(R.drawable.bg);
imageArray.add(R.drawable.bg);
ImageAdapter adapter = new ImageAdapter(this, imageArray);
viewPager.setAdapter(adapter);

现在像这样创建ImageAdapter

    public class ImageAdapter extends PagerAdapter {

        Context context;
        ArrayList<String> imageArray;

        public ImageAdapter(Context context, ArrayList<String> imageArray) {
            this.context = context;
            this.imageArray = imageArray;
        }

        @Override
        public int getCount() {
            return imageArray.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == ((ImageView) object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = new ImageView(context);

            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, 50);
            imageView.setLayoutParams(layoutParams);

            int padding = context.getResources().getDimensionPixelSize(R.dimen.font_size_10);
            imageView.setPadding(padding, padding, padding, padding);

//            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

            Glide.with(ProfileActivity.this)
                    .load(R.drawable.bg)
                    .into(imageView);


            ((ViewPager) container).addView(imageView, 0);

            return imageView;

        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((ViewPager) container).removeView((ImageView) object);
        }
    }

这篇关于使用默认的Android图像查看器显示图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆