您好我想在两个水平放置的textview之间绘制一个略微弯曲的分隔线。我不想在背景中放置任何类型的图像。我尝试过使用xml drawable但我的代码不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#ff0000" />
</shape>
</item>
<item
android:right="100dp"
android:left="-180dp"
android:top="-25dp"
android:bottom="-42dp">
<rotate
android:fromDegrees="15">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
我想设计图片中显示的布局。
答案 0 :(得分:2)
在这种情况下,您可以创建VectorDrawable
。请注意,在pre-lollipop版本中,无论如何都会生成图像,否则使用srcCompat
。
你的矢量绘图可能如下所示:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="24dp"
android:viewportWidth="36.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF0"
android:pathData="M0,0 L0,24 L20,24 L36,0 L0,0 Z"/>
为了根据您的需要提供更高的准确性,您应该自己编辑
答案 1 :(得分:1)
您可以像这样创建该形状
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
>
<TextView
android:id="@+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TADAA!!!"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textColor="@android:color/black"
android:background="@drawable/myshape"
/>
</LinearLayout>
myshape.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<size
android:width="100dp"
android:height="40dp" />
<solid android:color="#ff0" />
</shape>
</item>
<item
android:right="100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
<item
android:right="-100dp"
android:left="100dp"
android:top="-100dp"
android:bottom="-100dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</rotate>
</item>
</layer-list>
<强>输出强>
答案 2 :(得分:0)
在xml文件中尝试这个矢量drawable
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="99.0"
android:viewportWidth="338.0">
<path
android:fillColor="#000000"
android:pathData="M0,45.5l0,40.5 163.5,0 163.5,0 0,-40.5 0,-40.5 -163.5,0 -163.5,0 0,40.5zM176,10.6c0,0.3 -10.6,16.3 -23.5,35.5l-23.6,34.9 -61.9,0 -62,0 0,-35.5 0,-35.5 85.5,0c47,0 85.5,0.3 85.5,0.6zM322,45.5l0,35.5 -93.5,0 -93.6,0 18.7,-27.8c10.3,-15.2 21.2,-31.2 24.1,-35.5l5.4,-7.7 69.5,0 69.4,0 0,35.5z"
android:strokeColor="#00000000" />
</vector>