How can i get center x,y of my view in android?

前端 未结 5 1773
温柔的废话
温柔的废话 2020-12-29 19:29

I am attaching an imageview up on my frame layout. Here i want to get my imageview center co-ordinates. i will use that same co-ordinates to set my imageview in next layout.

5条回答
  •  执笔经年
    2020-12-29 20:18

    Try this :

    ImageView my_image = (ImageView) findViewById(R.id.my_imageView);  
    
    Rect rectf = new Rect();
    my_image.getLocalVisibleRect(rectf);
    
    Log.d("WIDTH        :",String.valueOf(rectf.width()));
    Log.d("HEIGHT       :",String.valueOf(rectf.height()));
    Log.d("left         :",String.valueOf(rectf.left));
    Log.d("right        :",String.valueOf(rectf.right));
    Log.d("top          :",String.valueOf(rectf.top));
    Log.d("bottom       :",String.valueOf(rectf.bottom));
    

    Hope this helps you.

    Thanks.

提交回复
热议问题