Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中的FloatingAction按钮上方添加文本视图_Android_Floating Action Button - Fatal编程技术网

如何在Android中的FloatingAction按钮上方添加文本视图

如何在Android中的FloatingAction按钮上方添加文本视图,android,floating-action-button,Android,Floating Action Button,我想在FloatingActionButton上方添加一个TextView,我使用FrameLayout作为TextView和FloatingActionButton的父布局,下面是我的示例代码: <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <android.support.design.widget.FloatingAct

我想在FloatingActionButton上方添加一个TextView,我使用FrameLayout作为TextView和FloatingActionButton的父布局,下面是我的示例代码:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#00fff0"
        app:borderWidth="0dp"
        android:elevation="0dp"
        app:fabSize="normal" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="above"/>

</FrameLayout>

我希望它像这样展示:


我很穷,有人能帮我吗?

这是一个z顺序问题。在FrameLayout中移动
以下是您的解决方案:

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

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


<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#00fff0"
    app:borderWidth="0dp"
    android:elevation="0dp"
    app:fabSize="normal" />

<TextView
    android:layout_toRightOf="@+id/fab"
    android:layout_marginLeft="-10dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="above"/>
</RelativeLayout>

</FrameLayout>

您只需向textview添加高程属性即可

 <FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.design.widget.FloatingActionButton
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="#00fff0"
        app:borderWidth="0dp"
        android:elevation="0dp"
        app:fabSize="normal" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="above"
        android:elevation="7dp"/>

</FrameLayout>


相应地设置两个视图的高程。此外,将TextView XML代码移到FAB XML代码上方对您更有意义。

要支持低端设备,请同时使用
android:elevation
app:elevation

将Fab的两个值都设置为0

 <FrameLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#00fff0"
    app:borderWidth="0dp"
    android:elevation="0dp"
    app:elevation="0dp"
    app:fabSize="normal" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="above"/>

    </FrameLayout>


我已经试过了,而且没用,很漂亮!对于API>21,它就像一个魔咒。不得不改为给电视加高度。这两件事你都可以做。为TextView提供高程或从FABWelcome中删除高程。。快乐编码:)使用
app:elevation
来支持低于API 21的版本。您将晶圆厂高程设置为零,如果晶圆厂没有高程,这是否违背了晶圆厂的目的。我的观点是,若不将app:FAB的高程设置为零,那个么这是行不通的。尝试将FAB设置为标高7,将textview设置为8,textview仍然不会显示在顶部。
 <FrameLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundTint="#00fff0"
    app:borderWidth="0dp"
    android:elevation="0dp"
    app:elevation="0dp"
    app:fabSize="normal" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:text="above"/>

    </FrameLayout>