I would like to take a RelativeLayout which has a bunch of sub views,
and mirror it along the X axis. I have followed the rotateView code
from the map example, but that one is subclassing a ViewGroup, not a
RelativeLayout (what's the difference by the way?)
The mirroring needs to be permanent, so while an animation would be
possible it is not desired (and during testing it also produced weird
side effects - the main view would flip but the child views would not
stay pinned correctly).
Here is my current code
public class MainScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FlipMainScreen ms = new FlipMainScreen(getApplication());
TextView testText = new TextView(getApplication());
setContentView(ms);
testText.setText("Mirror test");
ms.addView(testText);
}
}
public class FlipMainScreen extends RelativeLayout {
public FlipMainScreen(Context context) {
super(context);
this.setWillNotDraw(false);
}
@Override
protected void dispatchDraw(Canvas canvas) {
canvas.save(Canvas.MATRIX_SAVE_FLAG);
super.dispatchDraw(canvas);
Log.v("This",""+getWidth());
canvas.scale(-1f,1f, getWidth() * 0.5f, getHeight() * 0.5f);
canvas.restore();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int
b) {
final int width = getWidth();
final int height = getHeight();
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View view = getChildAt(i);
final int childWidth = view.getMeasuredWidth();
final int childHeight = view.getMeasuredHeight();
final int childLeft = (width - childWidth) / 2;
final int childTop = (height - childHeight) / 2;
view.layout(childLeft, childTop, childLeft + childWidth, childTop
+ childHeight);
}
}
}
The text view displays but it is not mirrored. Rather, it is centered
on the screen if I use the onLayout override.
How can I make the RelativeLayout flip completely, including all the
child views ?
(user interaction is obviously not required in that state)
--
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