简体   繁体   English

如何制作与屏幕成比例的浮动操作按钮?

[英]How can I make a floating action button which is proportional to the screen?

I want to make a FAB that grows in size when viewed on a larger screen. 我想制作一个在较大屏幕上观看时会增大大小的FAB。 Is it possible? 可能吗? If so what can I add to the normal FAB code. 如果是这样,我可以添加什么到正常的FAB代码中。

Edit:-Guys what i mean by my question is that I do not want the same size on a 5 inch and 10 inch screen. 编辑:-各位,我的意思是我不希望在5英寸和10英寸的屏幕上使用相同的尺寸。 I want the FAB to automatically change its size depending on the size of the screen. 我希望FAB根据屏幕大小自动更改其大小。

Thanks. 谢谢。

You can override the normal and mini sizes by adding the following to values/dimens.xml: 您可以通过将以下内容添加到values / dimens.xml中来覆盖普通尺寸和迷你尺寸:

  <!-- Overriding sizes of the FAB -->
  <dimen name="design_fab_size_normal">90dp</dimen>
  <dimen name="design_fab_size_mini">30dp</dimen>

The tricky thing would be if you need more than 2 fab sizes, in that case, I guess you need to create a custom view extending the fab. 棘手的事情是,如果您需要两个以上的晶圆厂尺寸,那么在这种情况下,我想您需要创建一个扩展晶圆厂的自定义视图。

You have to create Different values folder for different screens. 您必须为不同的屏幕创建不同的值文件夹。 Like: 喜欢:

values-sw720dp          10.1” tablet 1280x800 mdpi

values-sw600dp          7.0”  tablet 1024x600 mdpi

values-sw480dp          5.4”  480x854 mdpi 
values-sw480dp          5.1”  480x800 mdpi 

values-xxhdpi           5.5"  1080x1920 xxhdpi
values-xxhdpi           5.5"  1440x2560 xxhdpi

values-xhdpi            4.7”   1280x720 xhdpi 
values-xhdpi            4.65”  720x1280 xhdpi 

values-hdpi             4.0” 480x800 hdpi
values-hdpi             3.7” 480x854 hdpi

values-mdpi             3.2” 320x480 mdpi

values-ldpi             3.4” 240x432 ldpi
values-ldpi             3.3” 240x400 ldpi
values-ldpi             2.7” 240x320 ldpi


这就是它的样子

There is also another trick to accomplish this task, 还有另一个技巧可以完成此任务,
Choose LinearLayout and use android:layout_weight="n" for different views in order to automatically increase their size. 选择LinearLayout并将android:layout_weight="n"用于不同的视图,以自动增加其大小。

This answer is given by -@Javier Mendonca, @IntelliJ Amiya and Me 该答案由-@ Javier Mendonca,@ IntelliJ Amiya和Me给出

From the docs: 从文档:

Floating action buttons come in two sizes: the default and the mini. 浮动操作按钮有两种尺寸:默认和迷你。 The size can be controlled with the fabSize attribute. 大小可以通过fabSize属性控制。

This is, of course, not relating to the dimensions of the image assets you provide to the fab ImageView backing itself. 当然,这与您提供给fab ImageView支持本身的图像资产的尺寸无关。

If you use the default Floating Action Button image, its size will appear consistent across multiple screen resolutions, since its assets are managed by the design support library. 如果您使用默认的“浮动操作按钮”图像,则其大小将在多个屏幕分辨率下显示一致,因为其资产由设计支持库管理。 If you provide a custom image for your floating action button, then be sure to provide necessary asset dimensions. 如果您为浮动操作按钮提供了自定义图片,请确保提供必要的资产尺寸。

For more information see: https://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html#attr_android.support.design:fabSize 有关更多信息,请参见: https : //developer.android.com/reference/android/support/design/widget/FloatingActionButton.html#attr_android.support.design : fabSize

Try this hope this will help: 尝试这个希望对您有所帮助:

         <android.support.design.widget.FloatingActionButton
            android:id="@+id/floating_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin" //16dp
            android:background="?attr/colorPrimary"
            android:src="@drawable/ic_arrow_forward_white_24dp" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM