简体   繁体   English

Horizo​​ntalScrollView从/ drawable文件夹获取图像

[英]HorizontalScrollView Getting Images from /drawable folder

I am using HorizontalScrollView in order to create some Gallery-like option and right now I am getting the images from an folder in the external drive. 我正在使用Horizo​​ntalScrollView来创建一些类似于Gallery的选项,现在我正在从外部驱动器的文件夹中获取图像。 But I figured that I don't need, also shouldn't do that since the images I wanted to show is predetermined images. 但是我认为我不需要,也不应该这样做,因为我要显示的图像是预定图像。 So I will simply change the directory to the drawable folder but I am not sure which path to go. 因此,我只是将目录更改为drawable文件夹,但是我不确定该走哪条路径。 So right now I am getting the directory with this: String path1= Environment.getExternalStorageDirectory().getAbsolutePath(); 因此,现在我正在使用以下目录: String path1= Environment.getExternalStorageDirectory().getAbsolutePath();

I found two more methods for directory retrieval but I am not sure which one to use. 我发现了另外两种用于目录检索的方法,但是我不确定该使用哪种方法。

String path2 = Environment.getDataDirectory().getAbsolutePath();

String path3= Environment.getRootDirectory().getAbsolutePath();

First one returns "/mnt/sdcard" , second returns "/data" , third one "/system" . 第一个返回"/mnt/sdcard" ,第二个返回"/data" ,第三个返回"/system"

Which one should I use in order to reach /drawable folder inside this way? 为了通过这种方式进入/ drawable文件夹,我应该使用哪一个?

Which one should I use in order to reach /drawable folder inside this way? 为了通过这种方式进入/ drawable文件夹,我应该使用哪一个?

None of them. 没有一个。 Those are all for files on the filesystem. 这些全部用于文件系统上的文件。 Drawable resources are not files on the filesystem. 可绘制资源不是文件系统上的文件。

Use getResources().getDrawable() to retrieve a Drawable given its ID (eg, R.drawable.foo ). 使用getResources().getDrawable()检索给定其ID的Drawable (例如R.drawable.foo )。

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

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