私はアンドロイドが初めてです。ディレクトリに 1,000 を超える画像があります。グリッドビューで画像の親指を表示しています。次のコードで動作します。しかし問題は、ビューをロードするのに 45 秒かかることです。私はそれが必要です:ローダーでグリッドを表示し、画像を1つずつロードします。そのため、ユーザーは最後の画像が読み込まれるのを待つことができません。
コードは次のとおりです。
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ListRowHolder listRowHolder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.ll_sponsor_list_item,
parent, false);
listRowHolder = new ListRowHolder();
listRowHolder.imgSponsor = (ImageView) convertView
.findViewById(R.id.imggrid_item_image);
convertView.setTag(listRowHolder);
} else {
listRowHolder = (ListRowHolder) convertView.getTag();
}
try {
listRowHolder.imgSponsor
.setImageBitmap(decodeSampledBitmapFromResource(
ImageName.get(position)));
} catch (Exception e) {
Toast.makeText(ctx, e + "", Toast.LENGTH_SHORT).show();
}
return convertView;
}
public static Bitmap decodeSampledBitmapFromResource(String fileName) {
Bitmap picture = BitmapFactory.decodeFile(fileName);
int width = picture.getWidth();
int height = picture.getWidth();
float aspectRatio = (float) width / (float) height;
int newWidth = 98;
int newHeight = (int) (98 / aspectRatio);
return picture = Bitmap.createScaledBitmap(picture, newWidth,
newHeight, true);
}