我想通過URL將圖像獲取到我的項目中,我有多個圖像顯示在我的項目中,並且我也有圖像URL。我想要顯示的圖像翻頁或下一個按鈕按圖像的URL按下。我知道如何通過URL與畢加索圖書館顯示一張圖片,但顯示多張圖片,我無法做到這一點,所以幫助我這樣做,因爲我是新來的android。如何通過他們的URL顯示多個圖像
這裏是我的代碼,我用捲曲視圖效果顯示圖片...幫助我在這裏表現出通過URL圖像..
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import java.util.Objects;
public class Braids extends AppCompatActivity {
CurlView cv;
int index=0;
String type;
String abcd[]={"https://imgur.com/zSX6k5m.png","https://imgur.com/Xhjz9HC.png","https://imgur.com/8hOKrBf"};
ImageView img;
private int[] mBitmapIds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_braids);
cv = (CurlView) findViewById(R.id.curls);
type=getIntent().getExtras().getString("CheckShirt");
if(type.equals("braids")){
for(int i=0;i<abcd.length;i++)
{
//printing url
}
}
else if(type.equals("buns"))
{
mBitmapIds= new int[]{};
}
else if (type.equals("fallinghairs"))
{
mBitmapIds=new int[]{};
}
cv.setPageProvider(new PageProvider());
cv.setSizeChangedObserver(new SizeChangedObserver());
cv.setSoundEffectsEnabled(true);
cv.setCurrentIndex(index);
cv.setBackgroundColor(Color.BLACK);
cv.setAllowLastPageCurl(false);
}
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
@Override
public void onSizeChanged(int w, int h) {
if (w > h) { cv.setViewMode(CurlView.SHOW_TWO_PAGES);
}
else {
cv.setViewMode(CurlView.SHOW_ONE_PAGE);
}
}
}
private class PageProvider implements CurlView.PageProvider {
// Bitmap resources.
@Override
public int getPageCount() {
return mBitmapIds.length;
}
@SuppressLint("NewApi") 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 = 0;
int border = 0;
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();
}
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;
}
@Override
public void updatePage(CurlPage page, int width, int height, int index) {
Bitmap front = loadBitmap(width, height, index);
page.setTexture(front, CurlPage.SIDE_BOTH);
page.setColor(Color.argb(127, 255, 255, 255), CurlPage.SIDE_BACK);
}
}
}
你試過的東西到目前爲止 –
製作一個ImageUrl數組,然後在滑動或下一個按鈕按下通過下一個數組索引。 –
你可以從網址加載一個圖像,然後在下一個按鈕按下通過下一個圖像網址到畢加索和加載需求的下一個圖像。不預先加載所有圖像。 –