我正在尝试构建自定义水平滚动视图画廊,而不是在 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);
}