浮动操作按钮,文本垂直放置

问题描述 投票:0回答:1

我需要有一个圆圈(如浮动操作按钮),其文本居中,但不能水平缩放。如果缩放,则会变成椭圆形。我使用了一个圆like here,但拉伸后变成了椭圆形。我正在尝试使用fab,但我不知道如何实现它。文本始终远离圆。我的最低API级别是21。This is the end result how I want it to be如果仍然没有收到,请发表评论。

  <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>
android xml android-layout floating-action-button
1个回答
0
投票

尝试一下:

<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>
© www.soinside.com 2019 - 2024. All rights reserved.