创建一个不直的垂直线的分隔符

时间:2016-10-17 19:25:19

标签: java android android-layout

我可以像管道Uncaught exception, not in assertion. expected: nil actual: com.fasterxml.jackson.core.JsonGenerationException: Cannot JSON encode object of class: class java.io.ByteArrayInputStream: java.io.ByteArrayInputStream@4db77402 一样创建一个分隔符视图,例如:

|

但是,如何创建一个类似于<View android:layout_width="1dp" android:layout_height="match_parent" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:background="@color/black" /> /的分隔符,即一条不直的线?

2 个答案:

答案 0 :(得分:1)

您可以使用android:rotation属性。

e.g。

<View
    android:layout_width="1dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:rotation="45"
    android:background="@color/black" />  

答案 1 :(得分:1)

您可以创建自定义绘图,如下所示

<item>
    <rotate
        android:fromDegrees="45"
        android:toDegrees="45"
        android:pivotX="50%"
        android:pivotY="50%" >
        <shape
            android:shape="line"
            android:top="1dip" >
            <stroke
                android:width="1dip"
                android:color="#FF0000" />
        </shape>
    </rotate>
</item>

来源: https://stackoverflow.com/a/15239304/2179495