【问题标题】:FloatingActionButton is in the wrong placeFloatingActionButton 放错地方了
【发布时间】:2018-12-07 13:48:07
【问题描述】:
在我的 xml 文件中,我正在实现浮动操作按钮。它应该在右下角,但是当我运行我的应用程序时,它显示在左上角。它有什么问题?在我的 xml 文件中,声明 FAB 方向为底部 |结尾。这是我的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
></WebView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_help"
app:backgroundTint="#000000"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_below="@id/contacts"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_menu_delete"
app:backgroundTint="#000000"
/>
</RelativeLayout>
【问题讨论】:
标签:
android
xml
webview
widget
floating-action-button
【解决方案1】:
试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/contacts"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="60dp"
android:layout_marginRight="20dp"
android:layout_above="@+id/home"
app:backgroundTint="#000000"
app:srcCompat="@android:drawable/ic_menu_help" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/home"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:layout_alignParentEnd="true"
app:backgroundTint="#000000"
app:srcCompat="@android:drawable/ic_menu_delete" />
</RelativeLayout>
输出
【解决方案2】:
试试这个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_above="@+id/home"
android:layout_alignParentRight="true"
app:srcCompat="@android:drawable/ic_menu_help"
app:backgroundTint="#000000"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:srcCompat="@android:drawable/ic_menu_delete"
app:backgroundTint="#000000"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>