0

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);
}
4

2 に答える 2

0

クリック時にレイアウトパラメータをイメージビューに設定しようとしましたか?

于 2013-07-15T04:26:18.953 に答える
0

あなたはこのようなことをしなければなりません

画像を表示するには、次のようにインテントを開く必要があります。

インテント インテント = 新しいインテント(Intent.ACTION_VIEW); Uri uri = Uri.parse("android.resource://your.package.name/" + R.drawable.monk1,) intent.setData(uri); startActivity(意図);

于 2013-07-15T07:10:32.123 に答える