2016-06-16 123 views
2

的Fab按鈕,我想我的自定義圖標添加到FAB按鈕, 我指定它像自定義圖像

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@mipmap/ic_custom" /> 

其顯示圖標,但沒有完全填充晶圓廠,各地留下一定的餘量。

我希望我的圖標完全佔據晶圓廠尺寸和寬度(我的圖標是圓形的)

+0

dp中的圖標大小是多少? – jitinsharma

+0

我在所有資源中都有圖標'xhdpi','xxhdpi','xxxhdpi' –

+0

你試過更大尺寸的圖標嗎? – jitinsharma

回答

1

浮動動作按鈕會自動添加填充到圖標。它不會允許圖像佔據整個寬度/高度,這是違反guidelines

對於這樣的創建具有陰影/高程的自定義圓形ImageButton

0

一個簡單的修復: 使用相對佈局作爲根佈局。代替fab,使用正常的圖像視圖或按鈕,並根據需要將src設置爲自定義圖標和位置。假設您有一個ID爲「sv」的ScrollView,您可以在其上浮動按鈕。只需使用android:layout_above =「@ id/sv」,其中sv是您的ScrollView。

<ImageView 
android:id="@+id/floatingActionButton" 
android:layout_width="56dp" 
android:layout_height="56dp" 
android:layout_above="@id/sv" 
android:layout_alignParentBottom="true" 
android:layout_alignParentRight="true" 
android:layout_marginBottom="16dp" 
android:layout_marginEnd="16dp" 

android:clickable="true" 
android:onClick="edit" 
android:padding="0dp" 
android:scaleType="fitXY" 
android:src="@drawable/ic_pen" />