開發框架應用程序時,從Url和ImageView中放置。爲此,我想顯示來自url的圖像(幀)。該網址有超過50個圖像。對於這個我使用gridview,但它缺乏一些點,如查看圖片當用戶選擇
1.它的速度非常緩慢加載圖像。
2.我們在代碼時聲明圖像的名稱和大小,以便在發佈應用程序後不添加圖像。
我需要這些asap的解決方案。請任何人給我建議。
開發框架應用程序時,從Url和ImageView中放置。爲此,我想顯示來自url的圖像(幀)。該網址有超過50個圖像。對於這個我使用gridview,但它缺乏一些點,如查看圖片當用戶選擇
1.它的速度非常緩慢加載圖像。
2.我們在代碼時聲明圖像的名稱和大小,以便在發佈應用程序後不添加圖像。
我需要這些asap的解決方案。請任何人給我建議。
使用下面的延遲加載列表視圖的鏈接,這將幫助你。
使用上面的鏈接代碼,並添加其他活動和其他佈局選擇用於顯示圖像,如果u有不是告訴我任何問題,我會在這裏把完整的代碼。
1.加載圖像速度非常慢。
這取決於你的帶寬和設備緩存。
2.我們在代碼時聲明圖像的名稱和大小,以便在發佈應用程序後不添加圖像。
您可以預先定義的URL,以便在代碼時,可以追加圖像名稱url.and一旦你準備好網址後使用的AsyncTask下載圖片逐個\
下面的代碼片段會幫助你。
DownloadHelper.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);
}
}
感謝您的回答。但我需要用戶在網址中選擇圖片。該網址有更多的圖像用戶選擇一個和我需要在imageview中顯示的圖像。 – Shalini
請告訴我你做了什麼? –
我正在使用gridview。但需要解決方案而不是那個。顯示來自url的圖像,並選擇一個,並在imageview中修復它 – Shalini