android - 如何修复这个浮动按钮?
问题描述
按钮看起来很糟糕。按钮位于设备边缘,图标偏离中心。我是安卓新手。这是我的布局代码。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraZoom="15"
mapbox:mapbox_cameraZoomMax="17"
mapbox:mapbox_cameraZoomMin="8" >
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_location_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="320dp"
android:layout_marginLeft="320dp"
android:layout_marginTop="60dp"
android:tint="@android:color/white"
app:backgroundTint="@color/colorPrimary"
app:srcCompat="@android:drawable/ic_search_category_default" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="320dp"
android:layout_marginLeft="320dp"
android:layout_marginTop="150dp"
android:tint="@android:color/white"
app:backgroundTint="@color/colorPrimary"
app:srcCompat="@android:drawable/ic_menu_more" />
</com.mapbox.mapboxsdk.maps.MapView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我应该使用什么布局?我应该使用什么布局?我应该使用什么布局?
解决方案
对于图标,解决方案是使用属性 android:scaleType="center,示例代码如下:
<android.support.design.widget.FloatingActionButton
android:id="@+id/search_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_marginEnd="10dp"
android:src="@drawable/fab_search_icon"
app:backgroundTint="@color/colorPrimary"
app:elevation="4dp"
app:fabSize="normal"/>
推荐阅读
- java - 为什么我的 getTimeZone().getDisplayName 报告偏移量错误?
- xml - Google Maps API 给了我 net::ERR_ABORTED 400
- javascript - 将javascript数组元素写入文件
- python - input() 函数在哪个 Python 模块中?
- phpcs - PHPCS默认不能设置为PSR2
- javascript - 带有 Array 扩展类构造函数调用的 JS Array.prototype.filter
- java - 有没有办法检查Java在读取文本文件时是否开始读取文本文件中的新行
- kotlin - (不可变集合是可变的)在 Kotlin 中返回 true
- wordpress - 使用 woocommerce_email_actions 在地址保存上发送 WooCommerce 电子邮件
- java - 我的 GUI 无法识别我的实例方法。我怎样才能解决这个问题?