|
[android-beginners] Port AbsoluteLayout to any other Layout to draw at x,y : msg#01248AndroidBeginners
Hello, I'm a newbie to Android. I have a class PlaceMark that is basically a view that contains a drawable. The size of the view should be the size of the drawable(eg. icon.jpg) . Using AbsoluteLayout(supported in Android 1.1), I'm able to specify the x,y position on the screen that I want this view to be placed in (see function setPositionAndScale()). But AbsoluteLayout is obsolete in Android 1.5 What is the best way to port this code for target 1.5? Which Layout can I use and how do I use it to acheive the same outcome? I would really appreciate any help with this. Thanks, -MH I have this code to place a drawable import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.AbsoluteLayout; class PlaceMark extends View { private Drawable mDrawable; private int mPlaceMarkWidth; private int mPlaceMarkHeight; private int mScaledWidth; private int mScaledHeight; private float mScale = 1.0f; PlaceMark(Context context, Drawable drawable) { super(context); mDrawable = drawable; mPlaceMarkWidth = drawable.getIntrinsicWidth(); mPlaceMarkHeight = drawable.getIntrinsicHeight(); mScaledWidth = mPlaceMarkWidth ; mScaledHeight = mPlaceMarkHeight ; LayoutParams layout = new LayoutParams(mPlaceMarkWidth, mPlaceMarkHeight); this.setLayoutParams(layout); } public void setPositionAndScale(int x, int y, float scale) { mScale = scale; mScaledWidth = (int)(scale*mPlaceMarkWidth); mScaledHeight = (int)(scale*mPlaceMarkHeight); int xpos = x - (mScaledWidth /2); int ypos = y - (mScaledHeight); AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams (mScaledWidth , mScaledHeight, xpos, ypos); this.setLayoutParams(params); invalidate(); } @Override protected void onDraw(Canvas canvas) { mDrawable.setBounds(0, 0, mScaledWidth , mScaledHeight); mDrawable.draw(canvas); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@xxxxxxxxxxxxxxxx To unsubscribe from this group, send email to android-beginners-unsubscribe@xxxxxxxxxxxxxxxx For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---
|
|
||||||||||||||||||||||||||
| News | Mail Home | sitemap | FAQ | advertise |