Android放大和缩小图片

时间:2019-05-19 19:27:47

标签: android image

单击时我会放大和缩小图像。点击放大,并在5秒后放大。

我写了这个:

resimdnm.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));

 resimdnm.setScaleType(ImageView.ScaleType.FIT_CENTER);

 relativel.bringChildToFront(resimdnm);

SystemClock.sleep(5000);

resimdnm.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));

Resimdnm是一个ImageView Relativel是RelativeLayout

当我在那里删除时:

SystemClock.sleep(5000);

resimdnm.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));

图像放大。但是当我添加睡眠功能时。图片不会放大。

我该如何解决?

我需要你的帮助。

1 个答案:

答案 0 :(得分:0)

尝试:

resimdnm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            resimdnm.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
            resimdnm.setScaleType(ImageView.ScaleType.FIT_CENTER);


            if (resimdnm.getLayoutParams().height == RelativeLayout.LayoutParams.MATCH_PARENT && resimdnm.getLayoutParams().width == RelativeLayout.LayoutParams.MATCH_PARENT) {

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        resimdnm.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
                    }
                }, 5000);

            }

        }
    });