创建自定义复杂xml形状的android

问题描述 投票:-1回答:1

我如何在附件中创建形状,并将其用作TextView的背景?另外,请给我一个指向创建自定义复杂形状的指南的链接

attachment link

android android-studio android-xml android-drawable
1个回答
0
投票

要创建自定义形状,这是Github项目-ShapeOfView

从ShapeOfView,您可以使用com.github.florent37.shapeofview.shapes.DiagonalView

依赖关系:implementation 'com.github.florent37:shapeofview:(lastest version)'

尝试下面的代码:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <com.github.florent37.shapeofview.shapes.DiagonalView
            android:layout_weight=".5"
            android:layout_width="0dp"
            android:layout_height="40dp"
            app:shape_diagonal_angle="-10"
            app:shape_diagonal_position="right">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Text1"
                android:gravity="center"
                android:layout_gravity="center"
                android:textColor="@android:color/white"
                android:background="@drawable/bg_left_side"/>
        </com.github.florent37.shapeofview.shapes.DiagonalView>
        <com.github.florent37.shapeofview.shapes.DiagonalView
            android:layout_weight=".5"
            android:layout_width="0dp"
            android:layout_height="40dp"
            app:shape_diagonal_angle="-10"
            app:shape_diagonal_position="left">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Text2"
                android:gravity="center"
                android:layout_gravity="center"
                android:textColor="@android:color/white"
                android:background="@drawable/bg_right_side"/>
        </com.github.florent37.shapeofview.shapes.DiagonalView>
    </LinearLayout>

以上代码的输出是:enter image description here

我希望它对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.