在代码视图中设置设计后,FloatingActionButton不会在设计视图中显示

时间:2017-01-05 10:11:02

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

快乐的nu年。我在代码视图中设置了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>

2 个答案:

答案 0 :(得分:0)

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

<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" />

答案 1 :(得分:0)

它在设计视图中显示我用线性布局替换cordinatorLayout但可以运行应用程序。似乎这个代码只能在协调器布局下工作。还有更多的答案吗?