在倾斜​​的Andr​​oid文本视图 [英] Skewing a text view in Android

查看:88
本文介绍了在倾斜​​的Andr​​oid文本视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待复制在我的应用程序如下:

I'm looking to replicate the following within my application:

正如你所看到的,它基本上是一个按钮,增加/减少它所包含的文本视图的价值。这个按钮有三种可视状态 - >未pressed,减少和增加(如上图中所示,用户点击增加箭头和按钮出现在那面pssed在$ P $)

As you can see, its basically a button which increases/decreases the value of the text view contained within it. This button will have three visual states -> unpressed, decrease and increase (as seen in the image above, the user taps the increase arrows and the button appears pressed in on that side)

下面是我的3个按钮的状态目前:

Here are my 3 button states currently:

正如你所看到的,这个问题我已经是能够正确倾斜/旋转文本视图,它的外观在视觉上正确的,一起出现按钮倾斜时,它正在增加或减少。

As you can see, the problem I have is being able to correctly skew/rotate the text view so it looks visually correct and appears slanted along with the button when its being increased or decreased.

我已经尝试了两种不同的方法至今:

I have tried two different approaches so far:

  • 创建一个覆盖的OnDraw()方法歪斜画布自定义文本视图类:

  • Create a custom text view class which overrides the onDraw() method to skew the canvas:

@Override
public void onDraw(Canvas canvas) { 
   canvas.save(); 

   canvas.skew(0.2f, 0f);

   super.onDraw(canvas); 
   canvas.restore();
}

  • 整合 Rotate3dAnimation (来源<一个href="http://$c$c.google.com/p/android-eksempler/source/browse/trunk/BrowseableApiDemos/assets/src/com/example/android/apis/animation/Rotate3dAnimation.java?r=38">here)并用于许多不同的变化,以获得所需的结果,例如:

  • Integrate the Rotate3dAnimation class (source here) and used many different variations to get the desired result such as:

       Rotate3dAnimation skew = new Rotate3dAnimation(
              30, 0, centerX, centerY, 0, false);
       txtAmount.startAnimation(skew); 
    

  • 不幸的是,我不太得到了反映上面的第一个图像的精确结果。我越来越困惑与Z轴设定值,倾斜,旋转等。

    Unfortunately, I'm not quite getting the exact result that mirrors the first image above. I'm getting confused with setting values with the Z-axis, skew, rotate etc.

    我会非常AP preciate任何人的帮助,谁拥有这个东西的经验。在此先感谢

    I'd greatly appreciate any help from anyone who has experience with this stuff. Thanks in advance

    推荐答案

    嗯,我甚至尝试,我想出了这样的事情:

    Well I even tried and I came up with something like this:

     public class DemoActivity extends TextView {
        Context context;
        String firstText = "$120.00";
    
     public DemoActivity(Context context)
       {
        super(context);
        this.context = context;
    
       }
    
    
        @Override
        protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        setText(firstText);
        setTextSize(30);
        canvas.skew(1.0f, 0.3f);  //you need to change values over here
        Rotate3dAnimation skew = new Rotate3dAnimation(
                  -20, 30,200, 200, 0, false);   //here too
        startAnimation(skew);
    
            }
        }
    

    我得到一个输出为:

    I got an output as:

    我想改变的试验和错误的价值观能够解决您的问题。 希望它能帮助。

    I guess changing the values by trial and error can solve your problem. Hope it helps.

    这篇关于在倾斜​​的Andr​​oid文本视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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