10

Is there a way to hit a button, and have the same layout view but flipped horizontally/mirrored ? (with all it's components) or the only way is to create the same layout and rearrange the components?

user3387848
  • 131
  • 1
  • 1
  • 8
  • I only know about rotation: http://stackoverflow.com/questions/1930963/rotating-a-view-in-android – fersarr Mar 07 '14 at 22:40

4 Answers4

23

You can flip a layout by setting the View property scaleX to -1. So View#setScaleX(1f) is normal, and View#setScaleX(-1f) is flipped (visually).

To do it pre-Honeycomb, you can use scale properties in the general Animation library. Just set the animation duration to 0 for immediate look (note, the elements will still be in the normal locations).

DeeV
  • 35,865
  • 9
  • 108
  • 95
2

You can use setRotationY(float) method to flip over the Y axis. If you would call yourView.setRotationY(180f) it would flip it horizontally. Similarly, yourView.setRotationX(180f) would flip it vertically.

Please note that it flips on a 3D space, so if you'd flip for 90f, your view will practically be invisible.

Mert Kahraman
  • 445
  • 6
  • 10
0

if you have a button that flips the view horizontally or vertically, you should add 180f to the view's rotation so that the button flips the view on the first click and restore the rotation on the second click.

Because 360 rotation is equal to 0 rotation.

TextView myTextView=findViewById(R.id.my_text_view);

button.setOnClickListener(new View.OnClickListener(){
       @Override
       onClick(View v){

      myTextView.setRotationX(myTextView.getRotationX()+180f); //horizontal flip
    // myTextView.setRotationY(myTextView.getRotationY()+180f)  //vertical flip

}
}
Nasib
  • 1,173
  • 1
  • 13
  • 23
0

Try by adjusting gravity and rotation attribute of you container.

Ram Chhabra
  • 421
  • 8
  • 11