URL dan imageView tasvirini qanday sozlash mumkin

URLdan rasmni imageView-ga o'rnatish kerak. Men bir nechta echimni topdim, ammo ularning birortasi men uchun ishlamayapti.

Kimdir menga yordam berishi mumkin, iltimos?

0
"Men bir nechta echim topdim, lekin ularning birortasi men uchun ishlamaydi" - biz hech qanday yordamni sizga Minimal, Complete va Tasdiqlangan misol . Umuman olganda, ko'pchilik Android ishlab chiquvchilari rasmni yuklash kutubxonasini ishlatadi.
qo'shib qo'ydi muallif CommonsWare, manba

7 javoblar

Siz Picassoni http://square.github.io/picasso/ dan foydalanishingiz mumkin. Internetdagi tasvirlarni tasavvurga o'tkazish

1
qo'shib qo'ydi

Siz Picassoni http://square.github.io/picasso/ dan foydalanishingiz mumkin. Internetdagi tasvirlarni tasavvurga o'tkazish

1
qo'shib qo'ydi

Avval bu o'zgaruvchini e'lon qilishingiz kerak:

Bitmap bmp;

Va ushbu kodni qo'shing:

String imageUrl = "URL";
                InputStream in = new URL(imageUrl).openStream();
                bmp = BitmapFactory.decodeStream(in);

ImageView img_results_experience = (ImageView)view.findViewById(R.id.img_results_experience);
                    img_id.setImageBitmap(bmp);

Bu men uchun ishlaydi!

0
qo'shib qo'ydi

glide kutubxonasidan foydalaning:

sizning kursatkichingizda:

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}

Sizning faoliyatingiz/fragmentingizda:

// For a simple view:
@Override public void onCreate(Bundle savedInstanceState) {
  ...
  ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  Glide.with(this).load("YOUR URL").into(imageView);
}

// For a simple image list:
@Override public View getView(int position, View recycled, ViewGroup container) {
  final ImageView myImageView;
  if (recycled == null) {
    myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false);
  } else {
    myImageView = (ImageView) recycled;
  }

  String url = myUrls.get(position);

  Glide
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .crossFade()
    .into(myImageView);

  return myImageView;
}
0
qo'shib qo'ydi

glide kutubxonasidan foydalaning:

sizning kursatkichingizda:

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}

Sizning faoliyatingiz/fragmentingizda:

// For a simple view:
@Override public void onCreate(Bundle savedInstanceState) {
  ...
  ImageView imageView = (ImageView) findViewById(R.id.my_image_view);

  Glide.with(this).load("YOUR URL").into(imageView);
}

// For a simple image list:
@Override public View getView(int position, View recycled, ViewGroup container) {
  final ImageView myImageView;
  if (recycled == null) {
    myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, container, false);
  } else {
    myImageView = (ImageView) recycled;
  }

  String url = myUrls.get(position);

  Glide
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .crossFade()
    .into(myImageView);

  return myImageView;
}
0
qo'shib qo'ydi

Men https://github.com/bumptech/glide dan foydalanishni tavsiya qildim. Foydalanish juda oson.

Glide.with(this).load(URL_TO_IMAGE).into(imageView);

Lekin, unutmang, bog'liqliklar qo'shing:

repositories {
  mavenCentral()//jcenter() works as well because it pulls from Maven Central
}

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}
0
qo'shib qo'ydi

Men https://github.com/bumptech/glide dan foydalanishni tavsiya qildim. Foydalanish juda oson.

Glide.with(this).load(URL_TO_IMAGE).into(imageView);

Lekin, unutmang, bog'liqliklar qo'shing:

repositories {
  mavenCentral()//jcenter() works as well because it pulls from Maven Central
}

dependencies {
  compile 'com.github.bumptech.glide:glide:3.7.0'
  compile 'com.android.support:support-v4:19.1.0'
}
0
qo'shib qo'ydi