Android b/c でギャラリー ウィジェットを使用するのではなく、カスタムの水平スクロール ビュー ギャラリーを構築しようとしています。API 16 では非推奨です。水平スクロール ビューでの画像のサムネイル。コードは次のとおりです。
private Integer[] Imgid = {
R.drawable.monk1,
R.drawable.mon2,
R.drawable.mon3,
};
LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.Linear);
for(x=0;x<15;x++) {
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),Imgid[x]);
int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();
int newWidth = 200;
int newHeight = 200;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(0);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(getResources(),resizedBitmap);
ImageView imageView = new ImageView(this);
imageView.setPadding(2, 0, 9, 5);
imageView.setImageDrawable(bmd);
imageView.setTag(x);
imageView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
imgView.setImageResource(Imgid[]); // large imageview
}
});
linearLayout1.addView(imageView);
}