I have a ImageView
object inside a LinearLayout
. I'm setting an animation to the ImageView
which will move image view from point x to y. Now, starting point should be right corner of parent container. My question is , how do i get the dimension of the container in which the view is present. I don't see view.getParent().getWidth()
kind of method in view hierachy.
The width and height can be obtained by calling getWidth() and getHeight().
Each View has two different types of sizes: the measured width and height, which is basically how big it wants to be, and the width and height that are the actual dimensions they have after being laid out. The desired size cannot always be provided, e.g. a view could request a width larger than its parent's width.
Try this:
View parent = (View)view.getParent();
int width = parent.getWidth();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With