【问题标题】:FAB Icon Doesn't Fill ButtonFAB 图标不填充按钮
【发布时间】:2017-10-21 11:34:34
【问题描述】:

我的布局导致浮动操作 src 图标无法展开以填充按钮的整个视图是怎么回事?

我认为app:borderWidth="0dp" 可能会解决问题,但事实并非如此。加号图标仍然小于按钮(红色区域)。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/cat"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/chordButtons"
                android:orientation="vertical"  >
            </LinearLayout>

            <android.support.design.widget.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_margin="16dp"
                android:clickable="true"
                app:borderWidth="0dp"
                android:src="@drawable/ic_add_circle_outline_black_24dp"/>
        </LinearLayout>

    </ScrollView>

</RelativeLayout> 

【问题讨论】:

  • 你的工厂表现得像它想象的那样:) 看看这个材料设计link。您可以选择更大的图像或将 fabSize 设置为 mini 作为解决方法。
  • @NebojsaVuksic 添加 android.support.design:fabSize="0" (正常大小)没有解决它。可以提供代码吗?
  • fabSize mini 的值为 1。只需将 xml 中的 fabSize 属性设置为 mini。
  • 图标比普通或迷你中的按钮小。此外,无论如何我希望按钮是正常大小的。我需要找到一种方法让图标充满按钮中的整个空间,就像在 Google 日历等应用程序中看到的那样。
  • 你应该改用this图标。

标签: android xml material-design floating-action-button


【解决方案1】:

将属性app:useCompatPadding="false" 添加到FloatingActionButton

或,

您可以使用没有外圈的不同+ 图标。使用this 图标。

或,

您可以使用第三方库com.github.clans.fab.FloatingActionButton 来获得您想要的输出。

这是一个例子:

<com.github.clans.fab.FloatingActionButton
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/material_design_floating_action_menu_item1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_margin="16dp"
    android:clickable="true"
    android:src="@mipmap/ic_launcher"
    fab:fab_size="normal"
    android:visibility="visible"/>

输出:

希望对你有帮助~

【讨论】:

  • 我想我必须使用库,app:useCompatPadding="false" 不起作用。
  • 您是否尝试过不带任何外圈的不同 + 图标。检查我更新的答案。
【解决方案2】:

您使用了错误的图标。你的晶圆厂表现得像它应该做的那样。看资料guidelines

您应该使用this 而不是那个图标,以实现与 Google 日历应用程序中类似的工厂设计。

【讨论】:

    【解决方案3】:

    我不确定这是否是一个好方法,但它确实有效。我在dimens.xml 中添加了这一行。

        <dimen tools:override="true"
        name="design_fab_image_size">56dp</dimen>
    

    【讨论】:

      猜你喜欢
      • 2013-09-06
      • 1970-01-01
      • 2018-12-18
      • 2023-02-07
      • 2016-04-18
      • 2017-08-17
      • 1970-01-01
      • 2021-08-25
      • 2018-06-04
      相关资源
      最近更新 更多