Android imageview height 0 solution


Here is solution to get height of Imageview in Android:

1
2
3
4
5
6
7
8
9
10
11
12
13
final ImageView mapImageView = (ImageView) findViewById(R.id.singaporeMap);
       
        ViewTreeObserver vto = mapImageView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                LayerDrawable ld = (LayerDrawable) mapImageView.getBackground();
                int height = mapImageView.getHeight()/2;
                LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                params.setMargins(0, height, 0, 0);
                listView.setLayoutParams(params);
            }
        });

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.