1

私は現在Androidで作業しておりlistview、URLから画像をロードするように作成しました。次のコードでこれを達成しました

InputStream is = (InputStream) new URL("http://ka.35pk.com/uploadfiles/gamepic/090830121252.jpg").getContent();

Drawable d = Drawable.createFromStream(is, "pic name");
imageview.setImageDrawable(d); 

一度下にスクロールするまで、listview画像は読み込まれませんlistview。しかし、見えない部分にも正しくロードできlistviewます。つまり、リストビューに 100 枚の画像がある場合、一度に画面に表示されるのは 10 枚の画像だけです。これらの 10 枚の画像は最初からロードできません。これらの画像は正常に読み込まれ、再び上にスクロールすると、アンロードされた画像も読み込まれました。つまり、画面に表示されているときに読み込まれませんでした。私の英語で申し訳ありませんが、詳しく説明しました。listviewスクロールダウン/アップを使用せずに URL からすべての画像を読み込むにはどうすればよいですか。親切に私を助けてください。ありがとう。

4

1 に答える 1

2

この回答を確認してください。

アプリに多くの画像があり、メモリの問題もある場合は、独自の方法で処理する必要があります。

遅延読み込みを使用してリストビューで画像をダウンロードするように。他の画像については、リンク 2 のような別の方法を使用します。

スクロールの問題については、getView()次のようにアダプタのコードを確認してください。

public class ListViewAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public ListViewAdapter(Context con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        public int getCount() {
            // TODO Auto-generated method stub
            return SoapParser.title_date.size();
        }

        public Object getItem(int position) {
            // TODO Auto-generated method stub
            // return product_id1.size();
            return position;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            // return product_id1.get(position).hashCode();
            return position;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.row_tb, null);
                holder = new ListContent();

                holder.date = (TextView) v.findViewById(R.id.textView1);
                holder.actual = (TextView) v.findViewById(R.id.textView2);
                holder.targate = (TextView) v.findViewById(R.id.textView3);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }



            holder.date.setId(position);
            holder.actual.setId(position);
            holder.targate.setId(position);

            holder.date.setText(" " + SoapParser.title_date.get(position));
            holder.actual.setText(" " + SoapParser.title_actual.get(position));
            holder.targate
                    .setText(" " + SoapParser.title_targate.get(position));

            return v;
        }
    } 

レイアウトで他のビューを使用している場合は、それを作成してくださいandroid:focusable='false'

于 2013-01-03T07:33:23.113 に答える