浮点按钮与Android中的背景活动冲突?

时间:2016-09-28 10:12:21

标签: java android xml

.

问题是,当我点击浮动图像按钮时,背景布局也会调用。

我在下面附上了代码。

<RelativeLayout
    android:background="@color/white"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <TextView
        android:textColor="@color/md_black_1000"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        android:text="Today Date"
        android:id="@+id/today_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:layout_below="@+id/today_date"
        android:orientation="vertical" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="1.7"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

                <TextView
                    android:layout_weight="1"
                    android:gravity="center"
                    android:textColor="@color/md_black_1000"
                    android:text="Morning"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />


                <TextView
                    android:gravity="center"
                    android:layout_weight="1"
                    android:textColor="@color/md_black_1000"
                    android:text="Afternoon"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />



        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.0"

            android:orientation="horizontal" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginEnd="@dimen/activity_vertical_margin"
                android:id="@+id/ll1"
                android:layout_width="match_parent"
                 android:layout_height="match_parent"
                android:background="@drawable/rectangle"
                android:layout_weight="1.0"
                android:text="Morning" />



            <LinearLayout
                android:orientation="horizontal"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginEnd="@dimen/activity_vertical_margin"
                android:id="@+id/ll2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/rectangle"
                android:layout_weight="1.0"
                android:text="Afternoon" />

         </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="1.7"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_weight="1"
                android:gravity="center"
                android:textColor="@color/md_black_1000"
                android:text="Evening"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


            <TextView
                android:gravity="center"
                android:layout_weight="1"
                android:textColor="@color/md_black_1000"
                android:text="Night"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />



        </LinearLayout>

    <LinearLayout
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="horizontal" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginEnd="@dimen/activity_vertical_margin"
            android:id="@+id/ll3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/rectangle"
            android:layout_weight="1.0"
            android:text="evening" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginEnd="@dimen/activity_vertical_margin"
            android:id="@+id/ll4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/rectangle"
            android:layout_weight="1.0"
            android:text="Night" />
    </LinearLayout>

</LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_add_reminders"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_plus"
        app:backgroundTint="#ffffff"
        android:layout_marginBottom="18dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginEnd="0dp" />

</RelativeLayout>

如果有人需要其他代码,我很乐意为您提供。我无法弄清楚为什么它与背景活动发生冲突。

1 个答案:

答案 0 :(得分:0)

<RelativeLayout
    android:id="@+id/root_layout"
    android:background="@color/white"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <TextView
        android:textColor="@color/md_black_1000"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        android:text="Today Date"
        android:id="@+id/today_date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:layout_below="@+id/today_date"
        android:orientation="vertical" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="1.7"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

                <TextView
                    android:layout_weight="1"
                    android:gravity="center"
                    android:textColor="@color/md_black_1000"
                    android:text="Morning"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />


                <TextView
                    android:gravity="center"
                    android:layout_weight="1"
                    android:textColor="@color/md_black_1000"
                    android:text="Afternoon"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />



        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.0"

            android:orientation="horizontal" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginEnd="@dimen/activity_vertical_margin"
                android:id="@+id/ll1"
                android:layout_width="match_parent"
                 android:layout_height="match_parent"
                android:background="@drawable/rectangle"
                android:layout_weight="1.0"
                android:text="Morning" />



            <LinearLayout
                android:orientation="horizontal"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginEnd="@dimen/activity_vertical_margin"
                android:id="@+id/ll2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/rectangle"
                android:layout_weight="1.0"
                android:text="Afternoon" />

         </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_weight="1.7"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_weight="1"
                android:gravity="center"
                android:textColor="@color/md_black_1000"
                android:text="Evening"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


            <TextView
                android:gravity="center"
                android:layout_weight="1"
                android:textColor="@color/md_black_1000"
                android:text="Night"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />



        </LinearLayout>

    <LinearLayout
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:orientation="horizontal" >

        <LinearLayout
            android:orientation="horizontal"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginEnd="@dimen/activity_vertical_margin"
            android:id="@+id/ll3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/rectangle"
            android:layout_weight="1.0"
            android:text="evening" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:layout_marginEnd="@dimen/activity_vertical_margin"
            android:id="@+id/ll4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/rectangle"
            android:layout_weight="1.0"
            android:text="Night" />
    </LinearLayout>

</LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_add_reminders"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action_plus"
        app:backgroundTint="#ffffff"
        android:layout_marginBottom="18dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginEnd="0dp" />

</RelativeLayout>

活动

FloatingActionButton btn ;//Assume find view by Id
RelativeLayout rl ;//Assume find view by Id

rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Keep Empty
            }
        });

btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //do your code
            }
        });

尝试它会帮助你