简体   繁体   English

如何设置setImageResource,我有手机的图库图片的URI

[英]How to set setImageResource, I have URIs of the gallery images of my phone

I have all the URIs of my phone images from Gallery as: 我将来自图库的手机图像的所有URI设置为:

for(String item: items) {
    Log.d("Images", item);
}

its output are: 其输出是:

07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150425_131643.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_213547.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_213646.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221519.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221530.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221544.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221628.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222055.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222533_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222541_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222552_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222637_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222643_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150429_205140_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150429_205148_HDR.jpg

I want to populate these in gridview. 我想在gridview中填充这些。 We can set static image present in Drawable as: 我们可以将存在于Drawable中的静态图像设置为:

imageView.setImageResource(mThumbIds[position]);

where: 哪里:

private Integer[] mThumbIds = {
     R.drawable.ic_launcher,R.drawable.ic_launcher
};

My gridview is: 我的gridview是:

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="90dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
    />

I am wondering how I can set images dynamically, as I donn't know how many images are there in the gallery and their URIs until runtime. 我想知道如何动态设置图像,因为直到运行时我都不知道画廊中有多少图像及其URI。

You will need to use an Adapter that will populate the grids for you. 您将需要使用一个可以为您填充网格的适配器。 Wait till you have the information about the images, then populate the adapter appropriately. 等待直到获得有关图像的信息,然后适当地填充适配器。 A good tutorial showing how to use gridviews and populate them with images+text can be found here . 此处可以找到一个很好的教程,展示了如何使用gridviews以及如何使用图像和文本填充它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在列表中找到这些图像的Uris时,如何使用画廊使用意图从外部存储查看多个图像 - How do I use gallery to view multiple images from external storage using intents when I hava Uris of those images in a list 我需要设置setImageResource,暂停并更改为其他setImageResource - I would need to Set setImageResource, pause and change to different setImageResource 如何将图像从图库设置为滑块? - How do I set images from gallery to slider? 我如何让用户从图库中选择多个图像,并在选择它们时将它们按顺序放入队列中? - How can I have a user select multiple images from the gallery, and as they are selected have them put into a queue in order? Android:启动图库应用程序,选择多个图像,返回URI - Android: Launching gallery app, picking multiple images, returning URIs 如何将图库中的图像动态添加到我的 gridview? 我可以 go 到画廊,但图像没有被添加到我的 gridview - How can I add images from the gallery to my gridview dynamically ? I can go to the gallery but images aren't getting added to my gridview setImageResource上编号的图像 - numbered images on setImageResource Android 如何从我的设备手机中的图库中删除图像 - Android how to delete image from gallery in my device phone 如何使用 AsyncTask、RecyclerView 和 RecyclerView.Adapter 将手机中的图像获取到 RecyclerView? - How can I use AsyncTask, RecyclerView, and a RecyclerView.Adapter to get images from my phone into my RecyclerView? 如何setImageResource列表<Item> - How to setImageResource List<Item>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM