2017-07-21 19 views
1

我試圖使用浮動作爲選擇卡片視圖的指標。浮動動作按鈕的行爲隨機

我希望FAB定位在卡的右上方,並有一點重疊。我嘗試使用drawable實現相同的外觀,但由於該應用針對的是API 16+,因此我無法使用海拔將其拉到卡的上方。

使用此XML: -

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical"> 


    <android.support.v7.widget.CardView 
     android:id="@+id/suppTemplateCardViewList" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     card_view:cardCornerRadius="2dp" 
     card_view:contentPadding="10dp"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:orientation="vertical"> 

     <ImageButton 
      android:id="@+id/suppFunction" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" /> 

     <TextView 
      android:id="@+id/suppFunctionName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/selectorIndicator" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:fabSize="mini" 
     app:layout_anchor="@id/suppTemplateCardViewList" 
     app:backgroundTint="@color/blueish" 
     android:src="@drawable/ic_done" 
     app:layout_anchorGravity="top|end"/> 

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

我得到了這種行爲:

我使用

app:layout_anchorGravity 

標籤也試過,但無濟於事。 謝謝。

回答

2

我最終發現自己。顯然,xml中的順序非常重要,因此在卡視圖上方設置FAB使其工作。

0

"top|end"是問題的核心。改成"top|right|end"

+0

具有相同的行爲:( – Sami

+0

您是否嘗試應用程序:海拔和android:海拔?..應用程序是爲應用程序compat –

+0

嗯,因爲應用程序必須使用API​​ 16+,我不能使用海拔。 – Sami