将 TextView 中的文本与 drawableTop 对齐
Align text in TextView with drawableTop
我有这个TextView
:
<TextView
android:id="@+id/silverCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:contentDescription="silver"
android:drawableTop="@drawable/silver"
android:text="3" />
看起来像这样:
如何让 3
在 View
中居中,使其直接位于我用 android:drawableTop
设置的可绘制对象下方?
您需要使用 gravity
而不是 layout_gravity
:
<TextView
android:id="@+id/silverCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:contentDescription="silver"
android:drawableTop="@drawable/silver"
android:text="3" />
这将使 3
在 TextView
中居中显示在 drawable 的正下方,如下所示:
我有这个TextView
:
<TextView
android:id="@+id/silverCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:contentDescription="silver"
android:drawableTop="@drawable/silver"
android:text="3" />
看起来像这样:
如何让 3
在 View
中居中,使其直接位于我用 android:drawableTop
设置的可绘制对象下方?
您需要使用 gravity
而不是 layout_gravity
:
<TextView
android:id="@+id/silverCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:contentDescription="silver"
android:drawableTop="@drawable/silver"
android:text="3" />
这将使 3
在 TextView
中居中显示在 drawable 的正下方,如下所示: