Soru & Cevap

Urlden Resim Alırken Yükleniyor ifadesi ...

06.06.2014 - 05:31

Arkadaşlar aşağıdaki kod ile linkteki resimi gösterebiliyorum fakat bir türlü Asycntask ile indirim sırasında yükleniyor ifadesi çıkaramadım örnekte pek bulamadım yardımcı olabilirmisiniz?

 

[code]

mImaView = (ImageView) view.findViewById(R.id.xmlresim);
            Bitmap bimtBitmap = null;
            try {
                bimtBitmap = BitmapFactory.decodeStream((InputStream)new URL("http://media.dunyabulteni.net/250x190/2012/09/05/satilik-villa-8.jpg").getContent());
            } catch (MalformedURLException e1) {
             e1.printStackTrace();
            } catch (IOException e1) {
             e1.printStackTrace();
            }
    
            mImaView.setImageBitmap(bimtBitmap);

            usingSimpleImage(mImaView);

[/code] 

5 Görüntülenme

7 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user Oğuzhan61
Oğuzhan61
12.11.2014 - 10:37

Merhabalar ... Ben kodu uyguladım fakat söyle bir olay olıyor..

Örneğin 10 tane resim var ekranınımda.Bunlara default bir resim setledim.Sonra sırayla urlden resimleri getiriyor.Daha sonra ekranı aşagıya kaydırıp yukarı cıkaraınca üstte getirdiği resimler kayboluyor default resim görünüyor.SOnra tekrar urlden resimleri getiriyor...Aynı kodu kullandım acaba neden böyle oluyor...Yardım ederseniz sevinirim..

Profile picture for user FATIH_999
FATIH_999
07.06.2014 - 02:46

Aşağıdaki şekilde yaptım hocam ama çalıştıramadım

[code]

AnimationDrawable animation = new AnimationDrawable();
            animation.addFrame(getResources().getDrawable(R.drawable.tmp1), 60);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp2), 60);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp3), 60);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp4), 60);
            animation.setOneShot(false);

            ImageView imageAnim =  (ImageView) view.findViewById(R.id.simple); 
            new DownloadImageTask((ImageView) view.findViewById(R.id.simple)).execute("RESİM URLSİ");
            imageAnim.setImageDrawable(animation);
            animation.start();

[/code]

 

Sorunsuz çalışan animasyon kodum

[code]

public Resim extends Fragment {
    private ImageView mImaView;
     private AnimationDrawable animation;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
         
         View view = inflater.inflate(R.layout.caps, container, false);
            
         
         if (container == null) {

                return null;
            }

        animation = new AnimationDrawable();
            animation.addFrame(getResources().getDrawable(R.drawable.tmp0), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp1), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp2), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp3), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp4), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp5), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp6), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp7), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp8), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp9), 100);
            animation.setOneShot(false);        
            ImageView imageView = (ImageView)view.findViewById(R.id.simple); 
            imageView.setBackgroundDrawable(animation);
            imageView.post(new Starter());


  }
class Starter implements Runnable {

            public void run() {
                animation.start();        
            }

        }

[/code]

new DownloadImageTask((ImageView) view.findViewById(R.id.simple)).execute("RESİM URLSİ");

bunu nasıl entegre edeceğim hakkınızı helal edin vaktinizi alıyorum :)

picture-2176-1429627808.jpg
bekirdursun
07.06.2014 - 02:23

 

        AnimationDrawable animation = new AnimationDrawable();
        animation.addFrame(getResources().getDrawable(R.drawable.resim1), 60);
        animation.addFrame(getResources().getDrawable(R.drawable.resim2), 60);
        animation.addFrame(getResources().getDrawable(R.drawable.resim3), 60);
        animation.addFrame(getResources().getDrawable(R.drawable.resim4), 60);
        animation.setOneShot(false);

        ImageView imageAnim =  (ImageView) findViewById(R.id.imageView1); // Daha sonra internetten resim çekip yükleyeceğin imageview olmalı.
        imageAnim.setImageDrawable(animation);
        animation.start();

Profile picture for user FATIH_999
FATIH_999
07.06.2014 - 02:06

ama hareketli gif desteklemiyor herhalde çalışmadı gif resmi aşağıdaki kodla kendim oluşturdum hareketli resmi fakat yukarıdaki koda nasıl entegre edebilirin?

 

[code]

if (container == null) {

                return null;
            }


            animation = new AnimationDrawable();
            animation.addFrame(getResources().getDrawable(R.drawable.tmp0), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp1), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp2), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp3), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp4), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp5), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp6), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp7), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp8), 100);
            animation.addFrame(getResources().getDrawable(R.drawable.tmp9), 100);
            animation.setOneShot(false);        
            ImageView imageView = (ImageView)view.findViewById(R.id.simple); //mestrua imagen ok, en el fragmentus
            //animation 0
            imageView.setBackgroundDrawable(animation);
            imageView.post(new Starter());

[/code]

picture-2176-1429627808.jpg
bekirdursun
07.06.2014 - 12:03

Aşağıdaki kodu ekle;

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;
    
    public DownloadImageTask(ImageView bmImage) {
        this.bmImage = bmImage;
    }
    
    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap mIcon11 = null;
        try {
            InputStream in = new java.net.URL(urldisplay).openStream();
            mIcon11 = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return mIcon11;
    }
    
    protected void onPostExecute(Bitmap result) {
        bmImage.setImageBitmap(result);
    }
    
    }

 

Daha sonra da bunu;

        new DownloadImageTask((ImageView) findViewById(R.id.image)).execute(RESIM_URL_I__BURAYA_GELECEK);

 

Son olarak imageview içine bir de default image ekle ( yükleniyor gibi - https://hintkumasi.com/images/ajax-loader.gif ), daha şık durur.

 

Yada yine yukarıda verdiğim işlemi yapıp resmi çağırdığın yerde bir tane ProgressBar başlat, onPostExecute içinde ise o barı sonlandır. (2)

 

Diğer bir öneri ise 2.öneriyi kendi koduna uygula.

Fatih
07.06.2014 - 12:32
Çok teşekkür ederim süper oldu :)
Fatih
07.06.2014 - 01:04
ama hareketli gif desteklemiyor herhalde çalışmadı gif resmi :(
Bekir Dursun
07.06.2014 - 02:20
imageview gif'leri direkt çalıştırmıyor ancak animasyon şeklinde yapabilirsin. Gif'i resimlerine ayır ve aşağıda vereceğim kodu uygula, yorumda karışabilir.
Profile picture for user FATIH_999
FATIH_999
07.06.2014 - 10:59

Kullanmak istediğim yer burası hocam

[code]

public class Resim extends Fragment {
    private ImageView mImaView;
     private ProgressDialog progressdialog;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
         
         View view = inflater.inflate(R.layout.caps, container, false);
            mImaView = (ImageView) view.findViewById(R.id.simple);

            
            
            Bitmap bimtBitmap = null;
            try {
                bimtBitmap = BitmapFactory.decodeStream((InputStream)new URL("http://media.dunyabulteni.net/250x190/2012/09/05/satilik-villa-8.jpg").getContent());
            } catch (MalformedURLException e1) {
             e1.printStackTrace();
            } catch (IOException e1) {
             e1.printStackTrace();
            }
    
            mImaView.setImageBitmap(bimtBitmap);

            /**
             * Use Simple ImageView
             */
            usingSimpleImage(mImaView);
            
        
            return view;

        
     } 

[/code]

picture-2176-1429627808.jpg
bekirdursun
06.06.2014 - 05:56

Asynctask alanının tamamını yazarsan için ekleme yapabiliriz,