我需要有一个圆圈(如浮动操作按钮),其文本居中,但不能水平缩放。如果缩放,则会变成椭圆形。我使用了一个圆like here,但拉伸后变成了椭圆形。我正在尝试使用fab,但我不知道如何实现它。文本始终远离圆。我的最低API级别是21。如果仍然没有收到,请发表评论。
<FrameLayout
android:layout_width="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="0dp"
android:src="@android:color/transparent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=" 20 Left"
android:gravity="center"
android:elevation="16dp"
android:drawableTop="@drawable/ic_star_white"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>
尝试一下:
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_to_cart_floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="#800"
app:fabSize="normal" />
<TextView
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:elevation="7dp"
android:text="20"
android:textColor="#fff"
android:textStyle="bold" />
</RelativeLayout>