使用默认的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);
}
}