簡體   English   中英

創建自定義復雜 xml 形狀 android

[英]Create custom complex xml shape android

如何像在附件中一樣創建形狀,並將它們用作 TextViews 的背景? 另外請給我一個鏈接到創建自定義復雜形狀的指南

附件鏈接

要創建自定義形狀,這里是 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>

上述代碼的 output 為: 在此處輸入圖像描述

我希望這個對你有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM