1
public class LoadImageActivity extends Activity {

    ImageView image_view;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image_view = (ImageView)findViewById(R.id.imageview);
        me m1=new me();
        m1.execute("http://wallbase1.org/thumbs/rozne/thumb-499842.jpg");
        me m2=new me();
        m2.execute( "http://wallbase1.org/thumbs/rozne/thumb-637449.jpg"); 
        me m3=new me();
        m3.execute( "http://wallbase1.org/thumbs/rozne/thumb-2509834.jpg"); 
        me m4=new me();
        m4.execute( "http://wallbase1.org/thumbs/rozne/thumb-2501884.jpg"); 
        me m5=new me();
        m5.execute( "http://wallbase1.org/thumbs/rozne/thumb-2514440.jpg");
     };


     class me extends AsyncTask<String, Integer, Bitmap> {

        Bitmap b1;

        // private MainActivity m1;
        protected Bitmap doInBackground(String...params) {
            // TODO Auto-generated method stub
             try {

                  /* Open a new URL and get the InputStream to load data from it. */

                  URL aURL = new URL(params[0]);
                  URLConnection conn = aURL.openConnection();
                  conn.connect();
                  InputStream is = conn.getInputStream();

                  /* Buffered is always good for a performance plus. */
                  BufferedInputStream bis = new BufferedInputStream(is);

                  /* Decode url-data to a bitmap. */
                  Bitmap bm = BitmapFactory.decodeStream(bis);
                  b1=bm;

                  bis.close();
                  is.close();

              } catch (IOException e) 
              {

                  Log.e("DEBUGTAG", "Remote Image Exception", e);

              }

           return null;
       }

    @Override
        protected void onPostExecute(Bitmap result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);

            image_view.setImageBitmap(b1);
            Animation rotation = AnimationUtils.loadAnimation(LoadImageActivity.this, R.anim.rotate);
         image_view.startAnimation(rotation);
    }
        }}

インターネットからの画像をビットマップにデコードして表示しようとしていますが、複数のURLからの複数の画像を表示したいのですが、それを実装するためのより良い方法はありますか?

4

2 に答える 2

1

ダウンロードの期間は、さまざまなものによって異なります。現在、5つのAsyncTasksを生成しましたが、配信/実行の順序が、それらを生成した順序と同じになるという保証はありません。5番目の画像が最初に受信した画像である可能性があり、これにより完全に間違った順序になります。したがって、最初にすべてのイメージをダウンロードする必要があります。おそらく1つのAsyncTaskを使用します。その後、それが成功した場合は、アニメーションを開始して画像を切り替える必要があります。

于 2012-12-20T10:52:22.127 に答える
0

それを行うにはいくつかのより良い方法があり、それらはすべてコードよりもはるかに複雑です。しかし、あなたは良いスタートを切っています。

このGoogleI/ Oのビデオには、画像に関するいくつかの優れたテクニックがあります。4:40頃に確認してくださいhttps://www.youtube.com/watch?v=gbQb1PVjfqM

おそらく異なるサイズの異なる画像であるため、時間が異なります。

XMLR.anim.rotateコードを投稿して、アニメーションが機能しない理由を誰かが確認できるようにしてください。

于 2012-12-20T10:50:31.170 に答える