我已經將一組圖像加載到我的SD卡中,並且想在頁面捲曲活動中顯示它們。將圖像加載到頁面捲曲活動
我檢查,如果圖像正確下載:
ArrayList<String> mStringList= new ArrayList<String>();
File strPath = new File(Environment.getExternalStorageDirectory() + "/Pictures");
int lists = strPath.listFiles().length;
Log.d("number of items in array ",String.valueOf(lists));
File yourDir = new File(strPath, "");
for (File f : yourDir.listFiles()) {
if (f.isFile())
{
String name = f.getName();
String v = strPath + "/" + name;
mStringList.add(v);
}
}
這是位地圖提供商:
* Bitmap provider.
*/
private class PageProvider implements CurlView.PageProvider {
// Bitmap resources.
private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage,
R.drawable.taipei_101, R.drawable.world };
@Override
public int getPageCount() {
return 5;
}
private Bitmap loadBitmap(int width, int height, int index) {
Bitmap b = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF);
Canvas c = new Canvas(b);
Drawable d = getResources().getDrawable(mBitmapIds[index]);
int margin = 7;
int border = 3;
Rect r = new Rect(margin, margin, width - margin, height - margin);
int imageWidth = r.width() - (border * 2);
int imageHeight = imageWidth * d.getIntrinsicHeight()
/d.getIntrinsicWidth();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
imageWidth = imageHeight * d.getIntrinsicWidth()
/d.getIntrinsicHeight();
}
r.left += ((r.width() - imageWidth)/2) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight)/2) - border;
r.bottom = r.top + imageHeight + border + border;
Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;
d.setBounds(r);
d.draw(c);
return b;
}
如何更換
// Bitmap resources.
private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage,
R.drawable.taipei_101, R.drawable.world };
and Drawable d = getResources().getDrawable(mBitmapIds[index]);
到那些在我的SD卡?
http://whathaveyoutried.com? (認真的人,請問之前請嘗試一些) – njzk2
@ njzk2我設法將我的SD卡上的項目添加到String []數組中,但我不知道如何將它顯示到可繪製的d中。這就是我試過 – user1234555
我不明白你的意見。你可能試圖從確定如何枚舉SD卡上的圖像開始? – njzk2