Подтвердить что ты не робот

Как добавить TextView над FloatingActionButton в Android

Я хочу добавить TextView над FloatingActionButton, я использую 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>

но это бесполезно, TextView находится ниже FloatingActionButton, как это введите описание изображения здесь

и я хочу, чтобы это выглядело так: введите описание изображения здесь

Я беден за это, может ли кто-нибудь мне помочь?

4b9b3361

Ответ 1

вам просто нужен атрибут возвышения для 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>

Ответ 2

это задача z-порядка. В вашем FrameLayout переместите <TextView над <FloatingActionButton

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

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

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

должен сделать это

Ответ 3

Чтобы поддерживать низкоуровневое устройство, используйте как android:elevation, так и app:elevation

установите оба значения в 0 для Fab

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

Ответ 4

Вот ваше решение:

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

Ответ 5

Установите значения для обоих представлений соответственно. Кроме того, вам больше смысла перемещать XML-код TextView над кодом вашего FAB XML.