Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move ImageView around inside RelativeLayout

Tags:

android

I need to move an ImageView (or anything else, for that matter) around inside a RelativeLayout. Does any one know the proper way to do this?

like image 988
Joren Avatar asked Nov 02 '09 09:11

Joren


People also ask

How views are aligned inside a RelativeLayout?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

Which is better LinearLayout or RelativeLayout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

Is RelativeLayout deprecated?

relativelayout is deprecated now.

What is RelativeLayout and LinearLayout?

LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.


2 Answers

Makesure ImageView's layout_height and layout_width is set to fill_parent. Then do:

To move a view, use Matrix. It is very handy.

Matrix matrix = new Matrix();

matrix.reset();

matrix.postTranslate(x, y);

imageview.setScaleType(ScaleType.MATRIX);
imageview.setImageMatrix(matrix);
like image 155
whogiawho Avatar answered Sep 24 '22 05:09

whogiawho


this I found worked:

imageview.layout(l,t,r,b);
like image 45
Redsmurf Avatar answered Sep 21 '22 05:09

Redsmurf