Android 实现对角文本视图/布局效果

Android 实现对角文本视图/布局效果,android,android-layout,Android,Android Layout,在我玩的一个游戏中,我遇到了这种对角线效应,我想知道如何才能达到这种效果 所需输出 我以为我可以通过简单地调整旋转来达到效果,但那不起作用,我怎么能实现这样的布局呢 我可以应用一个看起来很相似的图像,但我也想为文本设置动画 compile 'com.haozhang.libary:android-slanted-textview:1.2' xml 视图的默认轴(X和Y值)为0,因此仅设置旋转将不起作用。以下是如何实现您想要的结果: 在XML中(设置宽度以扩展屏幕宽度并应用旋转) 在xmlan

在我玩的一个游戏中,我遇到了这种对角线效应,我想知道如何才能达到这种效果

所需输出

我以为我可以通过简单地调整旋转来达到效果,但那不起作用,我怎么能实现这样的布局呢

我可以应用一个看起来很相似的图像,但我也想为文本设置动画

compile 'com.haozhang.libary:android-slanted-textview:1.2'
xml

视图的默认轴(X和Y值)为0,因此仅设置旋转将不起作用。以下是如何实现您想要的结果:

在XML中(设置宽度以扩展屏幕宽度并应用旋转)


在xml
android:rotation=“10”
@ManoharReddy中为textview添加此属性,该属性不会像我之前尝试的那样生成所需的输出。输出是什么?你能分享屏幕截图吗?不是确切的输出,但它是一个接近的解决方案。谢谢
<com.haozhang.lib.SlantedTextView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_marginEnd="96dp"
    android:layout_marginTop="139dp"
    android:gravity="center"
    app:slantedBackgroundColor="@color/colorPrimaryDark"
    app:slantedLength="55dp"
    app:slantedMode="left"
    app:slantedText="Hello World"
    app:slantedTextColor="@color/colorPrimary"
    app:slantedTextSize="16sp" />
SlantedTextView stv = (SlantedTextView) findViewById(R.id.test);
stv.setText("This is a title")
        .setTextColor(Color.WHITE)
        .setSlantedBackgroundColor(Color.BLACK)
        .setTextSize(18)
        .setSlantedLength(50)
        .setMode(SlantedTextView.MODE_LEFT);
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="-100dp"
        android:layout_marginEnd="-100dp"
        android:gravity="center"
        tools:text="Your text"
        android:rotation="10" />
    yourTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            yourTextView.setPivotX(0);
            yourTextView.setPivotY(0);

            yourTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });