android - 文本视图形状显示为椭圆形,即使形状是圆形
问题描述
我创建了一个名为 circle.xml 的圆形:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#FFF" />
<size
android:width="5dp"
android:height="5dp"/>
<padding
android:left="5dip"
android:right="5dip"
android:top="5dip"
android:bottom="5dip" />
</shape>
在预览中,它看起来是圆形而不是椭圆形。然后我在我的文本视图中实现了它:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/addToCartBtn"
android:layout_width="match_parent"
android:text="@string/cart_button_text"
android:textColor="#FFF"
android:background="@color/colorPrimary"
android:layout_height="65dp"/>
<TextView
android:id="@+id/cartItemsCountTV"
android:elevation="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_alignStart="@id/addToCartBtn"
android:text="1"
android:textSize="16sp"
android:textStyle="bold"
android:background="@drawable/circle"/>
</RelativeLayout>
那么结果仍然是椭圆形:
仅当文本为两位数(例如“10”)时,形状才会变为圆形。为什么它是椭圆形的,即使它应该是圆形的?
解决方案
使用相同的layout_width
andlayout_height
将其保持为圆形而不是wrap_content
.
<TextView
....
android:layout_width="40dp"
android:layout_height="40dp"
..../>
使用 View 的大小
wrap_content
将强制它扩展到足以包含它包含的值(或子控件)的程度。
推荐阅读
- python - 在 x 轴上绘制频率
- sql-server - 如何存储 SQL 服务器查询
- r - 向量大小不能为 NA
- python - python mathplotlib savefig FileNotFoundError
- asp.net - 更改后 ASP.NET 站点未更新
- php - 即使存在路由,所有带有 multipart/form-data 的表单发布都会返回 404
- scala - 关于点菜数据类型的问题
- kubernetes - Kubernetes pod 处于未激活状态
- r - 如何使用变量动态选择数据框的子集
- ajax - 在 Laravel 5.8 中将每个 Ajax 的数据发送到控制器