我想通过URL将图像放入我的项目中,我有多个图像显示在我的项目中,我也有图像URL。我希望在页面翻转时显示图像,或者通过图像的URL按下一个按钮。我知道如何通过Picasso库通过URL显示一个图像但显示多个图像我无法做到这一点,所以帮助我这样做,因为我是android的新手。
这是我的代码,我正在显示带有卷曲视图效果的图像...帮我在这里通过网址显示图像..
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);
}
}
}
答案 0 :(得分:1)
如果您想在同一页面中显示,可以使用Facebook Fresco。
答案 1 :(得分:0)
您可以使用Glide库。 根据您的问题,您可以使用以下参考 https://www.androidhive.info/2016/04/android-glide-image-library-building-image-gallery-app/。希望这会对你有所帮助。