我找到了 this answer ,它确保 ImageView
的宽高比得以保留。
我如何使用带有可绘制背景的 TextView
来做到这一点?我有这个 TextView
:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:padding="5dp"
android:layout_margin="5dp"
android:text="1"
android:textColor="@color/white"
android:id="@+id/tvCount"
android:background="@drawable/textview_notify"
android:layout_column="2"
android:layout_gravity="right|top"/>
这是我的背景图:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<!-- The fill color -->
<solid android:color="@color/red" />
<!-- Just to add a border -->
<stroke
android:color="@color/white"
android:width="2dp"
/>
</shape>
如何确保 TextView
保持正方形(因此背景是完美的圆形?)。
最佳答案
使用android:gravity="center"
和android:padding="@dimen/circle_radius
。在dimens.xml中定义circle_radius
维度文件。
关于android - 如何保持 TextView 正方形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35655281/