所以,我正在使用harism,https://github.com/harism/android_page_curl的页面卷曲,并已成功实现它通过网络流加载图像。但是当我回到之前的图像或页面时,由于图像没有使用正确的索引,所以无法使其正常工作。即它们没有正常清爽。我无法弄清楚这一点。
这是我将图像加载到PageProvider
private class PageProvider implements CurlView.PageProvider {
@Override
public int getPageCount() {
return data1.size()-1;
}
private Bitmap loadBitmap(int width, int height, final int index) throws MalformedURLException, IOException {
Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF);
Canvas c = new Canvas(b);
System.out.println("value of current page index "+mCurlView.getCurrentIndex()+" and index is "+index);
System.out.println("url forward");
aq.ajax(data1.get(index+1), Bitmap.class,0, new AjaxCallback<Bitmap>() {
@Override
public void callback(String url, Bitmap object, AjaxStatus status) {
if(object!=null)
try {
System.out.println("url image downloaded "+url);
y=object;
aq.ajax(data1.get(index).replace(".png", ".mp3"), File.class,0,new AjaxCallback<File>() {
@Override
public void callback(String url, File object, AjaxStatus status) {
System.out.println("url sound downloaded "+url);
try {
if(object!=null)
{
FileInputStream inputStream = new FileInputStream(object);
if(index>0)
{
mPlayer.stop();
mPlayer.reset();
}
prepareMediaPlayer(inputStream.getFD());
inputStream.close();
}
}
catch (Exception e) {}
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
d = new BitmapDrawable(getResources(),y);
if(y!=null)
{
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);
}
//}
if(y==null)
return null;
else
return b;
}
@Override
public void updatePage(CurlPage page, final int width, final int height, final int index) {
Bitmap front = null;
System.out.println("motion / index value /countIteration / size of map "+motionDirection+"/"+index+"/"+countIteration+"/"+imageFilexxSm.size());
try {
front=loadBitmap(width, height,index);
if(front!=null)
{
page.setTexture(front, CurlPage.SIDE_FRONT);
page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}}}
我也尝试使用CurlView类中提供的getCurrentIndex
方法设置索引,但它甚至不起作用。已发现索引正确传递但位图未刷新。
更明显的问题是:
当我向前移动时,即第1,第2,第3,第4,第5 ......图像和声音正常工作,但是当我执行相反的第5,第4,第3,第2,第1,然后只有第5到第4卷曲是对的,但是第3,第2和第1都出了故障。为什么会这样?
答案 0 :(得分:2)
hm ... harism的curlpage在翻页时有加载图片的行为,例如如果你将页面从0翻转到1页面将加载第1页和第2页的图像,如果你翻到第5页curlpage将为第5页和第6页加载图像,但如果您回到第4页,curlpage将加载第4页,第3页和第2页的图像。
在onTouchloadImage()
时触发 ACTION.MOVE
,因此您必须在移动/翻转页面之前准备好图像,否则您的页面将变为空,您必须通过调用{{1}手动加载CurlView类中的方法。
updatePage()
,您可以在CurlView类的方法getCurrentIndex()
和startCurl()
中查看它。
答案 1 :(得分:2)
我希望如果使用图像加载库,这可以节省一些人的时间 浑厚的页面卷曲。
因此,经过大量研究后,我发现我使用(aquery)
的图像加载库已经得到了getCachedImage(String url)
,getCachedFile(String url)
这些方法,这些方法不适用于线程并返回{ {1}}如果文件尚未缓存到任何存储(sdcard,缓存目录)。
实际为我做的代码是,
null