Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get width of the container in which my view is added in Android

Tags:

android

view

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.

like image 612
prashant Avatar asked Feb 11 '11 11:02

prashant


People also ask

How do you find the height and width of a view?

The width and height can be obtained by calling getWidth() and getHeight().

What's the measurement in Android for views?

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.


1 Answers

Try this:

View parent = (View)view.getParent();
int width = parent.getWidth();
like image 179
svidnas Avatar answered Oct 11 '22 01:10

svidnas