1

フレームアプリケーションを開発しています。そのために、URLから画像(フレーム)を表示したい。URL には 50 を超える画像があります。そのために私は gridview を使用しますが、次のようないくつかの点が欠けています。

1.画像の読み込み速度が非常に遅い。

2. アプリケーションの公開後に URL に画像を追加しないように、コード時に画像の名前とサイズを宣言します。

早急にこれらの解決策が必要です。誰か私に提案してください。

4

2 に答える 2

1

遅延読み込みリストビューの以下のリンクを使用してください。これは役に立ちます。

遅延読み込みListView

上記のリンクコードを使用し、選択した画像を表示するための別のアクティビティと別のレイアウトを追加します。教えてくれるよりも問題がある場合は、ここに完全なコードを配置します。

于 2012-06-06T08:56:49.867 に答える
0

1.画像の読み込み速度が非常に遅い。

帯域幅とデバイスのキャッシュに依存します。

2. アプリケーションの公開後に URL に画像を追加しないように、コード時に画像の名前とサイズを宣言します。

URL を事前に定義できるので、コード時に画像名を url に追加できます。URL の準備ができたら、AsyncTask を使用して画像を 1 つずつダウンロードします \

以下のスニペットが役立ちます。

ダウンロードHelper.java

public interface DownloadHelper
{
    public void OnSucess(Bitmap bitmap);
    public void OnFailure(String response);
}

MainActivity.java

public class GalleryExample extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        DownloadHelper downloadHelper = new DownloadHelper()
        {
            @Override
            public void OnSucess(Bitmap bitmap)
            {
                ImageView imageView=(ImageView)findViewById(R.id.imageView);
                imageView.setImageBitmap(bitmap);
            }

            @Override
            public void OnFailure(String response)
            {
                Toast.makeText(context, response, Toast.LENGTH_LONG).show();
            }
        };
        new MyTask(this,downloadHelper).execute("image url");
    }

MyTask.java

public class DownloadTask extends AsyncTask<String, Integer, Object>
{
    private Context context;
    private DownloadHelper downloadHelper;
    private ProgressDialog dialog;


    public DownloadTask(Context context,DownloadHelper downloadHelper)
    {
        this.context = context;

    }

    @Override
    protected void onPreExecute()
    {
        dialog = new ProgressDialog(context);
        dialog.setTitle("Please Wait");
        dialog.setMessage("Fetching Data!!");
        dialog.setCancelable(false);
        dialog.show();
        super.onPreExecute();
    }

    @Override
    protected Object doInBackground(String... params)
    {
        URL aURL = new URL(myRemoteImages[position]);
        URLConnection conn = aURL.openConnection();
        conn.connect();
        InputStream is = conn.getInputStream();

        BufferedInputStream bis = new BufferedInputStream(is);
        /* Decode url-data to a bitmap. */
        Bitmap bm = BitmapFactory.decodeStream(bis);
        bis.close();
        is.close();
        return bm;
    }

    @Override
    protected void onPostExecute(Object result)
    {
        dialog.dismiss();
        if (result != null)
        {
            downloadHelper.OnSucess((Bitmap)result);
        } 
        else
        {
            downloadHelper.OnFailure("Error in Downloading Data!!");
        }
        super.onPostExecute(result);
    }
}
于 2012-06-06T07:47:29.090 に答える