如何使FloatingActionButton的自定义大小 [英] How to make custom size of FloatingActionButton

查看:642
本文介绍了如何使FloatingActionButton的自定义大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FloatingActionButton默认具有两种大小(普通和迷你).我需要另一个(比平常大).

FloatingActionButton by default has two sizes (normal and mini). I need another one (bigger than normal).

app:fabSize参数成为FloatingActionButton类中的private int mSize;变量.实际大小将由此功能确定:

app:fabSize parameter from xml became private int mSize; variable in FloatingActionButton class. The real size will be determined by this function:

final int getSizeDimension() {
    switch(this.mSize) {
    case 0:
    default:
        return this.getResources().getDimensionPixelSize(dimen.fab_size_normal);
    case 1:
        return this.getResources().getDimensionPixelSize(dimen.fab_size_mini);
    }
}

因为它被声明为final,所以我无法对其进行扩展.有任何想法吗?可以在我的应用程序中重新定义dimen.fab_size_mini资源吗?

Because it declared as final I can not extend it. Any ideas? May be I can redefine dimen.fab_size_mini resource in my app?

推荐答案

因为我没有使用mini大小的FAB,所以我重新定义了该大小.

Because I don't use FAB of mini size, I redefined this size.

dimens.xml:

dimens.xml:

<resources>
    <dimen name="design_fab_size_mini">100dp</dimen>
</resources>

layout.xml(第一个FAB大于第二个FAB):

layout.xml (first FAB will be bigger than second one):

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/addPhoto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        app:fabSize="mini"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="@dimen/fab_margin_right"
        android:src="@drawable/ic_photo_camera_white_24dp"

        />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/addPicture"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_alignParentBottom="true"
        android:layout_toLeftOf="@id/addPhoto"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="0dp"
        android:src="@drawable/ic_photo_white_24dp"
        />

这篇关于如何使FloatingActionButton的自定义大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆