【问题标题】:Android support design Floating Action ButtonAndroid 支持设计 Floating Action Button
【发布时间】:2016-01-04 16:10:37
【问题描述】:

我正在尝试减少 棒棒糖前 设备上的FAB 边距,但无论我做什么 - 没有任何改变。我创建了两个FABs 一个是在right|end|bottom 另一个是前一个。 16dp 的边距在 32dp 的两个 FABs 之间形成距离,这对我来说太大了。如果使用bottop_padding 向下按钮的可点击区域与第二个按钮重叠。也许,有人有同样的问题?请帮我!

here is picture of how it looks like

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/first"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/directions"
            app:backgroundTint="@android:color/holo_blue_light"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp"
            android:layout_above="@+id/uer_position"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/second"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/my_location"
            app:backgroundTint="@android:color/white"
            app:elevation="6dp"
            app:pressedTranslationZ="12dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        </RelativeLayout>

【问题讨论】:

  • 你能发布你的xml文件吗?
  • @MarianoZorrilla,完成
  • 那个16dp的边距是哪个?它们在哪里定义?
  • @MarianoZorrilla,我认为这对您没有帮助,因为边距不会以任何方式改变,即使是使用 viewTreeObservers 以编程方式。
  • @TimCastelijns 无处可去。我猜是系统。 imgur.com/BTb9EDq 这是它的样子

标签: android floating-action-button android-support-design


【解决方案1】:

在棒棒糖之前,边距会自动添加到FABs。创建一个名为values-v21 的新文件夹并创建一个名为xml 的文件dimes.xml 并添加以下行

 <dimen name="btn_fab_margins">16dp</dimen>

然后转到values 文件夹中的dimens.xml 并添加以下内容

<dimen name="btn_fab_margins">0dp</dimen>

现在在您的布局中向 FAB 添加以下内容

    android:layout_margin="@dimen/btn_fab_margins"

问题将得到解决。与 pre-lollipop 一样,它将占用 0dp 边距,而对于棒棒糖,它将占用 16dp 边距。

【讨论】:

  • 我已经这样做了,但使用了样式。棒棒糖之前的设备没有任何变化
  • 您确定为两个值文件都添加了维度吗?
  • 设置边距为0不要从截图中删除边距,
猜你喜欢
  • 1970-01-01
  • 2015-06-26
  • 2015-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多