【问题标题】:FloatingActionButton doesn't show in the design view after setting up the design in the code view在代码视图中设置设计后,FloatingActionButton 不显示在设计视图中
【发布时间】:2017-05-19 19:55:20
【问题描述】:

新年快乐。我在我的代码视图中设置了一个 floatingActionButton,但它没有在设计视图中显示该按钮。这里似乎有什么问题,我该如何解决?

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        app:layout_anchor="@id/viewOne"
        app:layout_anchorGravity="bottom|right|end"
        app:rippleColor="#FFFFff" />

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

【问题讨论】:

  • 没有问题,您可以尝试通过删除app:layout_anchor="@id/viewOne"来修复它
  • 如果您说您的代码有问题,您需要添加该代码!!!!!

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


【解决方案1】:

只需编写此代码..这将像魅力一样工作

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/fabCreateGroup"
    app:fabSize="normal"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_margin="15dp"
    android:scaleType="center"
    android:src="@drawable/youricon"
    app:backgroundTint="@color/colorPrimary" />

【讨论】:

  • 当我用线性布局替换cordinatorLayout但可以运行应用程序时,它显示在设计视图中。似乎此代码仅在其位于协调器布局下时才有效。还有其他答案吗?
【解决方案2】:

当我用线性布局替换cordinatorLayout但可以运行应用程序时,它显示在设计视图中。似乎此代码仅在其位于协调器布局下时才有效。还有其他答案吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多