Is it possible to increase Floating Action Button size on Android?

主宰稳场 提交于 2019-12-06 06:54:53

问题


I'm working on an application and we want to increase the size of our floating action button on larger devices.

The problem is that floating action button comes only in two size (mini and normal).

First, I tried to set a custom android:layout_heightand android:layout_heightto my fab but it didn't work. Well, the whole layout did actually got bigger but a border appeared around the fab and the background wasn't fully transparent.

Desperate for a solution I created my own circle button view and replaced the floating action button. But that's not good enough. I won't have the cool ripple effects or everything else a fab has.

After that, I started reading Floating Action Button's source code but it gets complex really fast so I decided to take a break and post my question here.

So, does anyone know how to increase the size of a floating action button?

EDIT 20/7/2016

My question is indeed similar to this one. However, I ask how to increase the default size of Button, not how to add a new size.


回答1:


The design library uses these parameters for the Fab:

<dimen name="design_fab_elevation">6dp</dimen>
<dimen name="design_fab_translation_z_pressed">6dp</dimen>
<dimen name="design_fab_content_size">24dp</dimen>
<dimen name="design_fab_size_normal">56dp</dimen>
<dimen name="design_fab_size_mini">40dp</dimen>
<dimen name="design_fab_border_width">0.5dp</dimen>

Ref

if you want to use your own Fab you can extend the design support library or copy the whole class and replace your own dimensions in the source code for example at

final int getSizeDimension() {
    switch (mSize) {
        case SIZE_MINI:
            return getResources().getDimensionPixelSize(R.dimen.design_fab_size_mini);
        case SIZE_NORMAL:
        default:
            return getResources().getDimensionPixelSize(R.dimen.design_fab_size_normal);
    }
}

Ref

But make sure you scale everything so the aspect ratio dose not change.




回答2:


If you want a quick solution, just define a fab and in code use

float val = 1.3f;
fab.setScaleY(val);
fab.setScaleX(val);


来源:https://stackoverflow.com/questions/34486504/is-it-possible-to-increase-floating-action-button-size-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!