我想建立自定義水平滾動視圖庫,而不是在android b/c中使用庫小部件,它在API 16中已棄用。我可以在滾動視圖中添加圖像,但我如何更改較大圖像視圖時,在水平滾動view.Here圖像的縮略圖各自用戶點擊是代碼水平圖像視圖庫
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);
}
不,爲什麼需要? – user2451541
你想增加imageview的大小嗎?或者你想預覽圖像? – dtheo