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! ;-)
No comments:
Post a Comment