如何显示Android的UI元素旋转大约180度 [英] How to display Android UI Elements about 180 degrees rotated

查看:716
本文介绍了如何显示Android的UI元素旋转大约180度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上显示的是Android XML布局文件中的一些UI元素。
我尽量让一个应用程序,其中两名球员可以坐在移动设备的两端,并互相对战。

I would like to display some UI Elements on a android xml layout file. I try to make an application, where two players can sit at each end of the mobile device, and play against each other.

所以需要显示一些按钮180度rotateted。

So need to show some Button 180 degrees rotateted.

这可能吗?我试着安卓重力,但这并没有工作。

Is this possible? I tried android:gravity, but this did not work.

感谢您的帮助,
马丁

Thanks for you help, Martin

推荐答案

我建议你看一看<一个href=\"http://stackoverflow.com/questions/2558257/%20how-can-you-display-upside-down-text-with-a-textview-in-android\">this螺纹,其中讨论了类似的问题。即使问题是关于一个TextView组件,巴顿扩展TextView的,所以它应该是微不足道的这个适应按钮。这个问题的任择议定书以下的onDraw()方法,最终定居:

I would suggest that you take a look at this thread, which discusses a similar issue. Even though the question is regarding a TextView component, Button extends TextView, so it should be trivial to adapt this to a button. The OP of that question eventually settled on the following onDraw() method:

@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's 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()方法的类和它的工作太棒了。

I will also say that I wrote a class which implemented this onDraw() method and it worked great.

这篇关于如何显示Android的UI元素旋转大约180度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆