【发布时间】:2021-09-26 19:07:04
【问题描述】:
我有一个可绘制形状的资源文件。
就是下面的drawable.xml代码。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="-2dp"
android:bottom="-2dp"
android:top="-2dp">
<shape android:shape="rectangle">
<stroke android:width="@dimen/px02"
android:color="@color/white" />
</shape>
</item>
</layer-list>
这是布局xml代码。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray333"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!!!"
android:textColor="@color/black"
android:background="@drawable/bg_category_border"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
结果是这样的。
您可以看到左侧的白条。
我想让栏的大小更短,顶部和底部与 TextView 的文本一样高。(红线)
我试图在 drawable.xml 中给出填充和大小。
我在 TextView 上设置了 android:includeFontPadding。
但它没有用。
我该怎么做??
【问题讨论】:
标签: android textview android-drawable android-shape