2016-11-01 51 views
0

Image Link浮動按鈕在某些設備

我提供我的應用程序的屏幕截圖在應用欄的中心進行調整。您可以看到浮動按鈕(在這種情況下,我使用了圖像按鈕並提供了圖像)未顯示完整,即其一半部分位於應用程序欄後面,應用程序欄呈綠色。儘管此相同的FAB按鈕在某些設備和版本(如4.2,4.3)中顯示完整,但在某些設備和我的5.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" 
android:id="@+id/coordinator_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#FFFFFF" 
android:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="190dp" 
    android:fitsSystemWindows="true" 
    android:background="@drawable/cvr1" 
    app:expanded="true"> 
    <!--android:theme="?attr/customAppBarOverlay"--> 


<android.support.design.widget.CollapsingToolbarLayout 
    android:id="@+id/toolbar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    app:contentScrim="?attr/colorPrimary" 
    app:layout_scrollFlags="snap"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:layout_collapseMode="pin" 
     android:background="@null"/> 


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

<include layout="@layout/content_main" /> 

<ImageButton 
    android:id="@+id/add_fab" 
    android:background="@drawable/starts" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_margin="@dimen/fab_margin" 
    app:layout_anchor="@id/app_bar" 
    app:elevation="0dp" 
    app:layout_anchorGravity="bottom|center" 
    /> 

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

我不知道究竟是什麼問題。我在互聯網上查過,但發現像這些線相同的解決方案,但仍然不顯示完整

app:layout_anchor="@id/app_bar" 
app:layout_anchorGravity="bottom|center" 

請幫助!

+0

,而不是固定的利潤率試'layout_centerVertical =「真」'和'layout_centerHorizo​​ntal =「真」' – rookieDeveloper

+0

沒有它不工作:( –

+0

相對佈局 – rookieDeveloper

回答

0

最佳實踐是使用支持庫提供的˚FA B(浮動操作欄)。

添加這的build.gradle文件:

compile 'com.android.support:design:24.2.1' 

而且CoordinatorLayout裏面試試這個:

<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:id="@+id/viewA" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.4" 
     android:background="@android:color/holo_purple" 
     android:orientation="horizontal"/> 

    <LinearLayout 
     android:id="@+id/viewB" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:background="@android:color/holo_orange_light" 
     android:orientation="horizontal"/> 

</LinearLayout> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:clickable="true" 
    android:src="@drawable/ic_done" 
    app:layout_anchor="@id/viewA" 
    app:layout_anchorGravity="bottom|right|end"/> 

這應該產生FAB如下面的圖片中提供:

enter image description here

爲了改變FAB的位置,您可以更改:

app:layout_anchorGravity="bottom|right|end"/> 

的首選方式爲佈局的理想位置。

+0

我試過這個,但它仍然不起作用,一半的FAB按鈕仍然隱藏在應用程序欄佈局 –

0

原因是您在按鈕上使用app:elevation="0dp"。由於AppBarLayout的默認標高爲4dp,因此在棒棒糖設備及更高版本上,該按鈕將被繪製在其下。

+0

它也不工作: –