Hello,

I have a zoomView which implements ViewGroup. I have then attached a
TextView to a RelativeLayout and that layout to the zoomView.

-zoomView
---RelativeLayout
------TextView

I override the onMeasure and onLayout method in zoomView. In onMeasure
I change the textSize depending on the zoom value and then try to
measure the rest of the RelativeLayout's size. In onLayout I change
the location of the RelativeLayout depending on the zoom and pan
level. This works very nice for zooming in but when I start to zoom
out it seems like the TextView's height locks and the text inside is
vertically centered in the TextView, this doesnt happen to the width.
This results in that the RelativeLayout's width goes back to the
original size but the height is still that of the highest zoom value.
If you find or think of anything please advice! Since I am new to the
Android scene I havent really figured out all the basic stuff yet.
Thanks.

onMeasure:

@Override
protected void onMeasure(int widthSpec, int heightSpec) {
    final float zoom = mState.getZoom();

    for (int index = 0; index < getChildCount(); index++) {
        final View child = getChildAt(index);
        final TextView name = (TextView)child.findViewById(R.id.name);
        name.setTextSize(18*zoom);
        child.measure(MeasureSpec.UNSPECIFIED,
MeasureSpec.UNSPECIFIED);
        child.measure((int)(child.getMeasuredWidth()*zoom), (int)
(child.getMeasuredHeight()*zoom));
    }

    setMeasuredDimension(widthSpec, heightSpec);
}

onLayout:

@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {

    final int viewWidth = getWidth();
    final int viewHeight = getHeight();

    final Rect rect = new Rect();
    final float panX = mState.getPanX();
    final float panY = mState.getPanY();
    final float zoom = mState.getZoom();

    for (int index = 0; index < getChildCount(); index++) {
        final View child = getChildAt(index);

        final int width = child.getMeasuredWidth();
        final int height = child.getMeasuredHeight();

        /** This is just tmp coordinates for testing */
        final int xcoord = 400;
        final int ycoord = 400;

        rect.left = (int)(zoom*(xcoord-((viewWidth*panX)-(viewWidth/
(zoom*2)))));
        rect.top = (int)(zoom*(ycoord-((viewHeight*panY)-(viewHeight/
(zoom*2)))));
        rect.right = (int)(rect.left + width);
        rect.bottom = (int)(rect.top + height);

        child.layout(rect.left, rect.top, rect.right, rect.bottom);
    }
}

The xml layout code looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android";
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:padding="10dip"
>
<TextView
    android:id="@+id/name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18dip"
    android:textColor="#fff"
    android:text="This"
    android:layout_centerInParent="true"
     />
</RelativeLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to