简体   繁体   中英

Android - How to show rotated textview in Triangle

Design

I use this xml code :

<RelativeLayout
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@drawable/bg_triangle_big_product"
                    android:visibility="@{viewModel.isBig == true ? View.VISIBLE : View.GONE}"
                    >
                    <TextView
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        android:text="@string/big_discount"
                        android:textSize="10sp"
                        android:paddingHorizontal="5dp"
                        android:rotation="-45"
                        fontPath="fonts/bebasneue_regular.ttf"
                        android:fontFamily="@font/bebasneue_regular"
                        android:gravity="center_horizontal|top"
                        android:lineSpacingExtra="-4dp"
                        android:ellipsize="end"
                        android:textColor="@color/white"
                        />
                </RelativeLayout>

but the background triangle is fixed, when you rotate the text, the paddings are not adjusted according to the triangle. Text is sticking out on the first line.

Result1 Result2

<TextView
            android:rotation="45"/>

Rotation simple rotates your TextView and about designing it, up to you, either use drawable.xml or any other way you see fit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM