简体   繁体   中英

Read image from drawable folder

I want to display images locally. Since i store the images in SD card it will not be available when i build the project.

Is there any other way to store local images other than SDcard, So that the images will be included in build file(.apk file).

GridView mGrid;
private static final String DIRECTORY = "/sdcard/Pictures/";
private static final String DATA_DIRECTORY = "/sdcard/Pictures/.ImageViewFlipper/";
private static final String DATA_FILE = "/sdcard/Pictures/.ImageViewFlipper/imagelist.dat";

Yes ofcourse you can store images either in Drawable folder or also in Assets folder.

If you stores images in Drawable folder then it will be compiled and index will be generated in R.java file but if you store images inside the assets folder then no index will be generated because assets folder is non-compiled folder.

public class imagegallery extends Activity {
    /** Called when the activity is first created. */
    Integer[] imageIDs = {

            R.drawable.img1,
            R.drawable.img2,
            R.drawable.img3,
            R.drawable.img4,
            R.drawable.img5,
            R.drawable.img6
    };
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       int position=2;
       ImageView imageView = (ImageView) findViewById(R.id.image);
       imageView.setImageResource(imageIDs[position]);
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM