I'm creating an activity - that has a floor plan on it with pins where things are found on the floor plan.
Here is the layout for the activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:windowSoftInputMode="stateHidden"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/layout">
<requestFocus />
</RelativeLayout>
I'm setting the RelativeLayout's background image as the floor plan.
private RelativeLayout _layout;
_layout = (RelativeLayout)findViewById(R.id.layout);
_layout.setBackground(new BitmapDrawable(getResources(), map));
I dynamically place pins (a png drawable packaged with my apk file) at various locations on the floor map. I create a relativelayout on the fly - then add an imageview (with the png file) then a TextView on the relativelayout (think like a gps pin with a number inside the pin).
RelativeLayout grouping = new RelativeLayout(this);
Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.symbol);
ImageView symbol = new ImageView(this);
symbol.setImageBitmap(img);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
grouping.addView(symbol);
TextView mapNum = new TextView(this);
grouping.addView(mapNum, params);
_layout.addView(grouping, params);
All of that is working great.
So in the activity, I'm also providing the ability to zoom in on the floor plan.
_layout.setScaleX(_scaling);
_layout.setScaleY(_scaling);
Once zoomed in, I allow the user to move around on the floor plan. That works great too. As you move around the floor plan the gps pins remain where they should be (all good).
The problem I'm running into -- is when I zoom in on the layout -- the pins are also being scaling. I'd like for the gps pins on the floor map to remain their original size.
Any pointers how to scale the parent, but not scale the child views?
I've ran to the similar problem while creating my own map. However answer is quite simple. When you make parent view twice as big (200%) you have to make children two times smaller (50%) to compensate scaling up. That way children should always look the same on screen. In my case I was using ScaleGestureDetector so when scaling parent I had to set scale to it's children like this:
float childScale = 1.0f / parentScale;
child->setScaleX(childScale);
child->setScaleY(childScale);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With