Skewing a text view in Android

后端 未结 2 874
无人共我
无人共我 2020-12-14 11:55

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

\"enter

As you

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 12:34

    Thanks to Parth Doshi answer. His answer need a little tweaking to run which I'm sharing here to save someone else time.

    First create a class in src folder and write all of three constructors.

    public class TextViewDemo extends TextView {
    
    Context context;
    String text = "TESTING 3DX TOOLS";
    
    public TextViewDemo(Context context) {
        super(context);
        this.context = context;
    }
    
    public TextViewDemo(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }
    
    public TextViewDemo(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
    }
    
    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        setText(text);
        setTextSize(30);
        canvas.skew(0.5f, 1.0f); // you need to change values over here
        Rotate3dAnimation skew = new Rotate3dAnimation(-50, 30, 0, 0, 0,
                false); // here too
        startAnimation(skew);
    
    }
    

    }

    In you res/layout/my_layout.xml file you can add a tag of your custom made TextView.

    
    />
    

    Like any other view, you can create an instance of TextViewDemo in your onCreate() method

    TextViewDemo txtDemo = (TextViewDemo) findViewById(R.id.name);
    

    Regards

提交回复
热议问题