— 29th January 2009
This was one of a series of posts I wrote on a short lived android dev blog I had during a period where I did a tiny bit of android app development.
Right now we’ve got an image on the screen (or some other kind of View) and you want to move it around. There's two things here, firstly the method you use for doing this and secondly the context you're in. This is the code you need:
LayoutParams params = new LayoutParams(100,100,100,200); image.setLayoutParams(params);The parameters you pass into that object are width,height,x,y so this is quite straight forward right? What you need to remember though is that there are different versions of LayoutParams depending on the type of ViewGroup you're using.
Above I was using a AbsoluteLayout so that LayoutParams object is imported from within this class.
import android.widget. AbsoluteLayout. LayoutParams;If you import (and therefore pass) the wrong kind of LayoutParams object to a View that’s within a different kind of ViewGroup this would cause problems (your app crashing). Eclipse isn't clever enough to sort this out for you so watch out! ;-)