我试图通过使用layer-list drawable设置Android中TextView的底部边框,但是问题是我看到底部的角落有点向上,但是textview下的直线不是。我希望它是不弯曲的完美直线。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- draw a 4 dp width border around the rectangle shape -->
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
<!--
hide left, top and right side border using white color
by padding 4 dp bottom side
-->
<item android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
</shape>
</item>
</layer-list>
<TextView
android:gravity="center"
android:text="@string/eat"
android:textSize="12sp"
android:background="@drawable/border_bottom_green_tab"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
答案 0 :(得分:1)
这将为您工作,只需将 android:bottom
的3dp更改为1dp<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:color="@color/colorPrimary" android:width="2dp"/>
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
</shape>
</item>
</layer-list>
答案 1 :(得分:0)
只需在前solid
中使用stroke
而不是item
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<!-- draw a 4 dp width border around the rectangle shape -->
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<!--
hide left, top and right side border using white color
by padding 4 dp bottom side
-->
<item android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
</shape>
</item>