【问题标题】:Horizontal image view gallery水平图像视图库
【发布时间】:2013-07-15 15:10:32
【问题描述】:

我正在尝试构建自定义水平滚动视图画廊,而不是在 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);
}

【问题讨论】:

    标签: android


    【解决方案1】:

    你必须这样做

    您需要打开一个意图来查看图像,如下所示:

    Intent 意图 = new Intent(Intent.ACTION_VIEW); uri uri = Uri.parse("android.resource://your.package.name/" + R.drawable.monk1,) 意图.setData(uri); 开始活动(意图);

    【讨论】:

      【解决方案2】:

      您是否尝试在点击时为 imageview 设置布局参数?

      【讨论】:

      • 你想增加图像视图的大小吗?或者你想预览图像?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 2017-02-26
      相关资源
      最近更新 更多