Scaling parent but not viewing by children

I am creating an activity - it has a floor plan with pins where things are 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 set the RelativeLayout 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 (png drawable packed with my apk file) in different places on the floor map. I create a relativelayout on the fly - then add an image (with a png file) and then a TextView on a relativelayout (think like a gps pin with a number inside a 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);

This all works great.

Thus, in this activity, I also provide an opportunity to scale up the plan.

_layout.setScaleX(_scaling);
_layout.setScaleY(_scaling);

After increasing, I allow the user to move around the floor. This works great. When you move on the floor plan, the gps pins stay where they should be (all is well).

, , - - . , gps .

, , ?

+4
1

. . (200%), (50%), . , . ScaleGestureDetector, :

float childScale = 1.0f / parentScale;
child->setScaleX(childScale);
child->setScaleY(childScale);
+1

Source: https://habr.com/ru/post/1531333/


All Articles