下面是在创建位图后从imageview数组添加图像并进行线性布局(水平滚动)的代码。
我如何设置onclicklistener到每个imageview(拇指)和点击拇指图像将显示在horizontall滚动条上方的大imageview?
由于在API 16中不推荐使用gallery小部件,这就是我使用此过程的原因。我在imageview数组中有大约15张照片。
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);
linearLayout1.addView(imageView);
}
ImageView.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
imgView.setImageResource(); // large imageview
}
});