Java 修改Android幻灯片以接受R.drawable中的字符串数组输入?
这里有一段优秀的简单Android幻灯片代码 如果使用R.drawable,效果非常好,但我有一组从游标数据获得的图像,需要知道如何转换 它们是否适合,因为它们位于字符串[]数组中,而不是整数[]Java 修改Android幻灯片以接受R.drawable中的字符串数组输入?,java,android,slideshow,Java,Android,Slideshow,这里有一段优秀的简单Android幻灯片代码 如果使用R.drawable,效果非常好,但我有一组从游标数据获得的图像,需要知道如何转换 它们是否适合,因为它们位于字符串[]数组中,而不是整数[] Integer[] imageIDs = { R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4 }; String[] image
Integer[] imageIDs = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4
};
String[] images = {
"/storage/extSdCard/image1.jpg",
"/storage/extSdCard/image2.jpg",
"/storage/extSdCard/image3.jpg",
"/storage/extSdCard/image4.jpg"
};
....
private void animatedSlideShow() {
slideShow = (ImageView)findViewById(R.id.slider1);
slideShow.setImageResource(imageIDs[index%imageIDs.length]); //--- Need to modify
index ++;
Animation showImage = AnimationUtils.makeInAnimation(this,true);
slideShow.startAnimation(showImage);
}
我的问题是:如何调整slideShow.setImageResource以接受字符串数组
如何调整slideShow.setImageResource以接受字符串
阵列
由于images
数组包含SD卡内的图像路径,imageID
包含应用程序可绘制文件夹内的图像id
要显示来自图像的图像
:
1.将SD卡中的图像作为文件读取:
File imgFile = new File(index%images.length]);
2.使用BitmapFactory.decodeFile
从imgFile
获取位图
:
Bitmap imgBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
3.调用ImageView的setImageBitmap
以在ImageView中显示图像:
slideShow.setImageBitmap(imgBitmap);
如何调整slideShow.setImageResource以接受字符串
阵列
由于images
数组包含SD卡内的图像路径,imageID
包含应用程序可绘制文件夹内的图像id
要显示来自图像的图像
:
1.将SD卡中的图像作为文件读取:
File imgFile = new File(index%images.length]);
2.使用BitmapFactory.decodeFile
从imgFile
获取位图
:
Bitmap imgBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
3.调用ImageView的setImageBitmap
以在ImageView中显示图像:
slideShow.setImageBitmap(imgBitmap);
如何调整slideShow.setImageResource以接受字符串
阵列
由于images
数组包含SD卡内的图像路径,imageID
包含应用程序可绘制文件夹内的图像id
要显示来自图像的图像
:
1.将SD卡中的图像作为文件读取:
File imgFile = new File(index%images.length]);
2.使用BitmapFactory.decodeFile
从imgFile
获取位图
:
Bitmap imgBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
3.调用ImageView的setImageBitmap
以在ImageView中显示图像:
slideShow.setImageBitmap(imgBitmap);
如何调整slideShow.setImageResource以接受字符串
阵列
由于images
数组包含SD卡内的图像路径,imageID
包含应用程序可绘制文件夹内的图像id
要显示来自图像的图像
:
1.将SD卡中的图像作为文件读取:
File imgFile = new File(index%images.length]);
2.使用BitmapFactory.decodeFile
从imgFile
获取位图
:
Bitmap imgBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
3.调用ImageView的setImageBitmap
以在ImageView中显示图像:
slideShow.setImageBitmap(imgBitmap);
使用类似于:
使用类似于:
使用类似于:
使用类似于:
您需要通过以下方式将可绘制内容添加到幻灯片中:
for(int i = 0; i < images.length; i++) {
Drawable myDrawable = new BitmapDrawable(getResources(), images[i]);
slideShow.setImageDrawable(myDrawable);
}
for(int i=0;i
您需要通过以下方式将可绘制内容添加到幻灯片中:
for(int i = 0; i < images.length; i++) {
Drawable myDrawable = new BitmapDrawable(getResources(), images[i]);
slideShow.setImageDrawable(myDrawable);
}
for(int i=0;i
您需要通过以下方式将可绘制内容添加到幻灯片中:
for(int i = 0; i < images.length; i++) {
Drawable myDrawable = new BitmapDrawable(getResources(), images[i]);
slideShow.setImageDrawable(myDrawable);
}
for(int i=0;i
您需要通过以下方式将可绘制内容添加到幻灯片中:
for(int i = 0; i < images.length; i++) {
Drawable myDrawable = new BitmapDrawable(getResources(), images[i]);
slideShow.setImageDrawable(myDrawable);
}
for(int i=0;i
请避免只回答代码问题。考虑添加解释,请避免只使用代码。考虑添加解释,请避免只使用代码。考虑添加解释,请避免只使用代码。考虑添加一个解释谢谢这个-它很好,但我仍然没有看到图像,虽然Logcat显示了正确的路径,每一个顺序,和Android Studio(设备监视器)也显示了文件在正确的地方,即I/Sturt/ExtSDCAR/FiNeNAM.JPG等;但我的设备上没有显示图像@首席执事:在真实设备上测试?是(三星SM-G313M);但现在只有当我将.getAbsolutePath更改为.getCanonicalPath时,它才起作用!不知道为什么,但这可能与谷歌在我的KitKat(4.4.2)上设置的R/W限制有关吗?谢谢你-它工作正常,但我仍然看不到图像,尽管Logcat显示了每个顺序的正确路径,Android Studio(设备监视器)也在正确的位置显示了文件,ie/storage/extSdCard/filename.jpg等;但我的设备上没有显示图像@首席执事:在真实设备上测试?是(三星SM-G313M);但现在只有当我将.getAbsolutePath更改为.getCanonicalPath时,它才起作用!不知道为什么,但这可能与谷歌在我的KitKat(4.4.2)上设置的R/W限制有关吗?谢谢你-它工作正常,但我仍然看不到图像,尽管Logcat显示了每个顺序的正确路径,Android Studio(设备监视器)也在正确的位置显示了文件,ie/storage/extSdCard/filename.jpg等;但我的设备上没有显示图像@首席执事:在真实设备上测试?是(三星SM-G313M);但现在只有当我将.getAbsolutePath更改为.getCanonicalPath时,它才起作用!不知道为什么,但这可能与谷歌在我的KitKat(4.4.2)上设置的R/W限制有关吗?谢谢你-它工作正常,但我仍然看不到图像,尽管Logcat显示了每个顺序的正确路径,Android Studio(设备监视器)也在正确的位置显示了文件,ie/storage/extSdCard/file