我正在尝试在我的应用中创建一个浮动按钮.按钮在那里,但按钮中的图像有点向上(见图像).
我无法弄清楚它有什么问题.下面是浮动按钮的XML的一部分.
<android.support.design.widget.FloatingActionButton
android:id="@+id/buttonUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginTop="480dp"
android:clickable="true"
android:scaleType="center"
android:src="@drawable/btn_back_to_top_3x"
app:layout_anchor="@id/layout"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="@android:color/background_light"
app:fabSize="normal" />
Run Code Online (Sandbox Code Playgroud)
按钮显示我想要的位置.唯一的问题似乎是里面的图像不是中心.为什么会这样?
编辑:经过一些更多的环顾四周我意识到图像本身存在问题,其中图像实际上没有居中,底部有空间(导致图像向上推).
我正在尝试使用FAB,但内部的图标位于按钮的右下角:
这是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>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?