简体   繁体   中英

How to add TextView over Floating Action Bar

I'm trying to add a TextView over Floating Action Bar but ended up like this. I will use that textField to show an integer.

在此处输入图片说明

This is my layout file

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/viewA"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:background="#0094d6"
            android:orientation="horizontal"
            android:gravity="center_vertical|center_horizontal">

        </LinearLayout>

        <LinearLayout
            android:id="@+id/viewB"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5"
            android:orientation="horizontal"
            android:background="#421575">

            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="@dimen/activity_vertical_margin">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="100"
                    android:background="#000000"
                    android:padding="10dp"
                    android:textColor="#FFFFFF"
                    android:layout_gravity="bottom"
                    android:layout_alignParentBottom="false"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true" />
            </RelativeLayout>

        </LinearLayout>



        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#A12545"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:paddingBottom="5dp">


            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/commentBox"
                android:layout_weight="3"
                android:hint=""
                android:maxLength="200" />



            <Button
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/sendButton"
                android:text=""
                android:layout_weight="1.5" />
        </LinearLayout>

    </LinearLayout>



    <android.support.design.widget.FloatingActionButton
        android:id="@+id/like"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/delete"
        app:layout_anchor="@id/viewA"
        app:layout_anchorGravity="bottom|right|end"
        app:backgroundTint="@color/not_liked" />



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

How can I show the field above Floating Action Bar. Thank You

You can order your layout like this

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.FloatingActionButton
        ...
        app:layout_anchorGravity="bottom|right|end"
        ...
    />

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        ...

    </LinearLayout>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM