如何在浮动操作栏上添加TextView

时间:2016-06-14 09:17:48

标签: java android xml

我试图在浮动操作栏上添加TextView,但结果却是这样。我将使用该textField来显示一个整数。

enter image description here

这是我的布局文件

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

如何在浮动操作栏上方显示该字段。 谢谢

1 个答案:

答案 0 :(得分:0)

您可以像这样订购您的布局

<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>
相关问题