创建自定义复杂的XML形状Android [英] Create custom complex xml shape android

查看:61
本文介绍了创建自定义复杂的XML形状Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

attachment link

推荐答案

要创建自定义形状,这里是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>
上述代码的输出为:

我希望它对您有效。

这篇关于创建自定义复杂的XML形状Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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