How to get the width and height of an android.widget.ImageView?

后端 未结 10 1898
长情又很酷
长情又很酷 2020-11-22 16:53
╔══════════════════════════════════════════════╗   ^
║ ImageView    ╔══════════════╗                ║   |
║              ║              ║                ║   |
║              


        
10条回答
  •  一个人的身影
    2020-11-22 17:44

    Post to the UI thread works for me.

    final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
    
    iv.post(new Runnable() {
                @Override
                public void run() {
                    int width = iv.getMeasuredWidth();
                    int height = iv.getMeasuredHeight();
    
                }
    });
    

提交回复
热议问题