Android 浮动操作按钮图标未在内部居中
我试图使用一个晶圆厂,但里面的图标位于按钮的右下角: 这是xml中的FAB定义:Android 浮动操作按钮图标未在内部居中,android,material-design,Android,Material Design,我试图使用一个晶圆厂,但里面的图标位于按钮的右下角: 这是xml中的FAB定义: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <com.google.android.material.floatingactionbutton.FloatingActionButton a
<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>
我做错了什么?而不是
android:src
尝试app:srcCompat
。FAB是你唯一正在使用的东西,因为如果它是(根据你发布的图片判断),也许你不需要RelativeLayout作为父母,你可以使用android:layout\u gravity=“bottom | end”在升级到SDK 28后,我也遇到了同样的问题。更改大小、缩放类型、布局和重力等将返回相同的结果
我目前的短期解决方案是使用ImageButton。这似乎是设计支持库v28.0.0中的一个bug 我可以通过编程方式设置scaleType来解决这个问题 在Java/Kotlin代码中:
centerLocationButton.setScaleType(ImageView.ScaleType.CENTER)
试一试
在晶圆厂。为我工作我的解决方案是
app:fabCustomSize=“56dp”
在我的情况下运行ok此解决方案
app:fab_icon=“@drawable/btn_back_to_top_3x”
不
android:src=“@drawable/btn\u back\u to\u top\u 3x
你可以加上
android:scaleY=“1.X”
android:scaleX=“1.X”
如果您使用的是材质设计和自定义尺寸,则要了解其他变化:
android:layout_width="80dp"
android:layout_height="80dp"
而不是
android:layout_width="wrap_content"
android:layout_height="wrap_content"
解决方法是使用这两个属性
app:fabCustomSize="80dp"
app:maxImageSize="70dp"
确保这一点
app:fabCustomSize = the same size as your layout_width
app:maxImageSize= about 10dp minus the size of your layout_width
请尝试给定的解决方案。它对我有效
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="end|bottom"
android:layout_margin="10dp"
android:backgroundTint="@color/white"
android:contentDescription="Chat"
app:fabCustomSize="75dp"
android:src="@drawable/chat"
app:borderWidth="1dp"
app:useCompatPadding="true" />
向您展示@drawable/ic_my_location
这是关于您在FAB src中使用的图像。这个答案可能有用:可能重复的可能重复:是的,我最后做了同样的事情。
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_gravity="end|bottom"
android:layout_margin="10dp"
android:backgroundTint="@color/white"
android:contentDescription="Chat"
app:fabCustomSize="75dp"
android:src="@drawable/chat"
app:borderWidth="1dp"
app:useCompatPadding="true" />