How to display Android interface elements 180 degrees

I would like to display some user interface elements in an android xml layout file. I am trying to make an application in which two players can sit on each end of a mobile device and play against each other.

Therefore, you need to show some button with a rotation of 180 degrees.

Is it possible? I tried android: gravity, but that didn't work.

Thanks for the help, Martin.

+3
source share
4 answers

, . , TextView, Button TextView, . onDraw():

@Override
public void onDraw(Canvas canvas) {
    //This saves off the matrix that the canvas applies to draws, so it can be restored later. 
    canvas.save(); 

    //now we change the matrix
    //We need to rotate around the center of our text
    //Otherwise it rotates around the origin, and that bad. 
    float py = this.getHeight()/2.0f;
    float px = this.getWidth()/2.0f;
    canvas.rotate(180, px, py); 

    //draw the text with the matrix applied. 
    super.onDraw(canvas); 

    //restore the old matrix. 
    canvas.restore(); 
}

, , onDraw(), .

+5

180 .

Android, .

0

What you can do is extend the Button view and override the onDraw () method.
This gives you a canvas that you can then rotate, and then call super.onDraw () so that the system clicks the button after it is rotated.

0
source

You can also use this sample. This is better because you do not need to move objects around Y.

canvas.save();

canvas.scale(1f, -1f, super.getWidth() * 0.5f,
    super.getHeight() * 0.5f);

canvas.drawBitmap(arrow,
    rect.centerX() - (arrow.getWidth() * 0.5F), rect.bottom,
    null);

canvas.restore();
0
source

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


All Articles