代码之家  ›  专栏  ›  技术社区  ›  laptou

Android中的角点

  •  -2
  • laptou  · 技术社区  · 7 年前

    create a Drawable that has rounded corners ,它可以用作其他控件的背景,以便使它们具有圆角的外观。

    但是,我希望我的角是棱角分明的,就像这样:

    enter image description here

    而且最重要的是,我希望剪裁的角保持相同的大小,而不管它应用到对象的大小(就像圆角一样),这意味着我不能只使用矢量可绘制,如果控件的大小与可绘制控件的大小不同,则矢量可绘制将拉伸形状。

    我将如何实现我想要的效果(最好是不涉及任何Java的解决方案)?

    1 回复  |  直到 7 年前
        1
  •  0
  •   laptou    7 年前

    我最终达到了使用可绘制图层列表的效果:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:gravity="left" android:right="14.5dp" android:top="14.5dp">
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="line">
                <stroke
                    android:width="1dp"
                    android:color="#000000"
                    android:dashWidth="2dp"
                    android:dashGap="1.4dp" />
            </shape>
        </item>
        <item android:gravity="right" android:bottom="14.5dp">
            <rotate
                android:fromDegrees="-45"
                android:toDegrees="0"
                android:pivotX="100%"
                android:pivotY="0%">
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="line">
                <stroke
                    android:width="1dp"
                    android:color="#000000"
                    android:dashWidth="2dp"
                    android:dashGap="1.4dp" />
                <size android:width="22.3dp" android:height="22.3dp" />
            </shape>
            </rotate>
        </item>
    </layer-list>
    

    为了显示这个可绘制的,我使用了一个ImageView:

    <ImageView
                android:layout_width="match_parent"
                android:layout_height="16dp"
                android:scaleType="fitXY"
                android:layerType="software"
                android:src="@drawable/fg_dotted_line" />
    
    推荐文章