【发布时间】:2014-07-02 15:51:51
【问题描述】:
我有一个代码可以动态地将图像和图像视图添加到我的应用程序中。我想为所有图像视图设置一个 onClick,以便在单击每个图像时,图像会完整显示,就像当您单击 facebook 图像时它会打开并且您可以单击下一个和上一个一样。我已经看到了很多其他问题和答案,但没有一个符合我的要求。
final int[] images = { R.drawable.abi1, R.drawable.abi2, R.drawable.abi3,
R.drawable.abi4 };
LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.bottomView);
for (int x = 0; x < images.length; x++) {
final Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
images[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) {
}
});
linearLayout1.addView(imageView);
}
【问题讨论】:
-
您已经在 imageView 上设置了 OnClickListener。你能更具体地谈谈你的问题吗?您是在问如何实现 onClick() 方法以全屏显示图像?
-
由于您有 OnClickListener(如循环所述),您始终可以制作自定义“弹出窗口”,其中已显示单击的图像,然后添加您自己的下一个/上一个按钮将显示下一个/上一个图像,如果有的话。但是我同意Loop,你应该解释得更好,这是什么问题?
-
@Loop 我在问如何为图像实现 onClick() 侦听器,以便它完全按照 Elven 所说的那样工作
-
@Elven 是的......这就是我要问的......我如何实现弹出窗口??
标签: android image bitmap imageview