我正在尝试构建自定义水平滚动视图库而不是在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);
}
答案 0 :(得分:0)
点击进行操作时,您是否尝试将设置参数设置为imageview?
答案 1 :(得分:0)
你必须做这样的事情
您需要按如下方式打开查看图像的意图:
Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(“android.resource://your.package.name/”+ R.drawable.monk1,) intent.setData(URI); startActivity(意向);