是否可以在Android上增加“浮动操作按钮"的大小? [英] Is it possible to increase Floating Action Button size on Android?

查看:90
本文介绍了是否可以在Android上增加“浮动操作按钮"的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我们希望在较大的设备上增加浮动操作按钮的大小.

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

问题在于浮动操作按钮只有两种尺寸(mininormal).

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

首先,我尝试为我的晶圆厂设置自定义android:layout_heightandroid:layout_height,但是它不起作用.好吧,整个布局实际上变大了,但是晶圆厂周围出现了边框,背景也不是完全透明的.

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.

此后,我开始阅读Floating Action Button的源代码,但是它变得非常复杂,因此我决定稍作休息,并在此处提出问题.

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?

编辑20/7/2016

我的问题确实类似于这一个.但是,我问如何增加Button的默认大小,而不是如何增加新的大小.

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.

推荐答案

设计库将这些参数用于Fab:

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>

参考

如果要使用自己的Fab,可以扩展设计支持库或复制整个类,并在源代码中替换自己的尺寸,例如,

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);
    }
}

参考

但是请确保缩放所有内容,以使宽高比不变.

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

这篇关于是否可以在Android上增加“浮动操作按钮"的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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