android - float 操作按钮图标未在内部居中

标签 android material-design

我正在尝试使用 FAB,但里面的图标位于按钮的右下角:

FAB with icon not centered

这是 xml 中的 FAB 定义:

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/centerLocationButton"
            style="@style/Widget.MaterialComponents.FloatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_margin="@dimen/pro_arriving_map_location_button_padding"
            android:src="@drawable/ic_my_location"
            app:backgroundTint="@color/white"
            app:fabSize="mini" />

    </RelativeLayout>

我做错了什么?

最佳答案

这似乎是设计支持库 v28.0.0 中的错误。

我可以通过以编程方式设置 scaleType 来解决这个问题。

在您的 Java/Kotlin 代码中:

centerLocationButton.setScaleType(ImageView.ScaleType.CENTER)

关于android - float 操作按钮图标未在内部居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52635233/

相关文章:

java - 如何在android wear中实现手势识别

android - Android 中的缅甸语语音到文本转换?

android - 使用 Android Studio 3.1 构建项目时出错并构建 :gradle 3. 1.0

android - 如何对 Kotlin Flow 中包含的列表中的元素调用方法

android - 单击 AVD 管理器图标时出错

android - 将 Toolbar 设置为 ActionBar 时出错

Android 退出转换 excludeTarget 在 android.support.v4.widget.DrawerLayout 中不起作用

css - 使用 makeStyles 在另一个选定类中嵌套类

android - 将样式应用于警报对话框

Angular Material 多选在隐藏时获取选定值