2017-08-06 71 views
1

我試圖實現在屏幕的右下角浮動按鈕,但底部利潤率不因某種原因失效:/我試圖改變邊距尺寸只在底部,但它沒有工作。浮動操作按鈕底邊距不起作用

佈局文件:

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
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:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

app_bar_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
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" 
tools:context="de.js_labs.gaminggroups.MainActivity" 
android:id="@+id/appBarMainRl"> 

<include 
layout="@layout/some_content" // Changed by LayoutInflater in Java ... 
android:layout_width="match_parent" 
android:layout_height="match_parent" /> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

</android.support.design.widget.CoordinatorLayout> 

some_content.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
app:useCompatPadding="true" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingTop="50dp" 
android:id="@+id/contentMyGroupsRl" 
tools:context=".MainActivity"> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/ic_action_addgroup" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    app:fabSize="normal" 
    android:layout_margin="@dimen/fab_margin" 
    android:layout_alignParentBottom="true" /> 

</RelativeLayout> 

截圖:https://i.stack.imgur.com/COpgF.png

回答

1

首先,嘗試刪除此行

android:layout_alignParentBottom="true" 

FloatingActionButton

第二步,移動FloatingActionButton從相對佈局CoordinatorLayout本身,作爲一個直接子

應該是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
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" 
tools:context="de.js_labs.gaminggroups.MainActivity" 
android:id="@+id/appBarMainRl"> 

<include 
layout="@layout/some_content" // Changed by LayoutInflater in Java ... 
android:layout_width="match_parent" 
android:layout_height="match_parent" /> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/ic_action_addgroup" 
    android:layout_alignParentEnd="true" 
    android:layout_alignParentRight="true" 
    app:fabSize="normal" 
    android:layout_margin="@dimen/fab_margin" 
/> 

</android.support.design.widget.CoordinatorLayout> 
+0

謝謝: )我kown這個工作,但有沒有可能把浮動按鈕,在內容佈局文件?或者我應該在更改內容佈局時將其隱藏起來? @ Janik174當您更改佈局 – janik174

+0

,你可以使用fab.hide()和fab.show()方法來改變動畫的知名度。 –

0

試試這個:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.CoordinatorLayout 
    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" 
    tools:context="de.js_labs.gaminggroups.MainActivity" 
    android:id="@+id/appBarMainRl"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

<android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end|bottom" 
     app:srcCompat="@drawable/ic_action_addgroup" 
     app:fabSize="normal" 
     android:layout_margin="@dimen/fab_margin" /> 

    </android.support.design.widget.CoordinatorLayout> 
+0

此代碼的工作,但有可能把浮動按鈕,在內容佈局文件? – janik174

+0

是嘗試添加** **並在某些從佈局晶圓廠**的Android刪除此:layout_alignParentBottom =「真」 **,看看作品 –

+0

rememenber保留一些佈局像你這樣的問題只有刪除**機器人:layout_alignParentBottom =「真」 ** @ Janik174 –

0

嘗試在FloatingActionButton標籤添加app:useCompatPadding="true"如下圖所示:

<android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginBottom="@dimen/activity_horizontal_margin" 
     android:layout_marginEnd="@dimen/activity_horizontal_margin" 
     android:layout_marginRight="@dimen/activity_horizontal_margin" 
     android:scaleType="center" 
     app:fabSize="mini" 
     app:useCompatPadding="true" />