简体   繁体   English

浮点按钮与Android中的后台活动冲突吗?

[英]Floating Point Button clashes with background activity in Android?

。

The problem is when I am tapping on floating image button the background layout is also call. 问题是当我点击浮动图像按钮时,也会调用背景布局。

I have below attached the code also. 我下面也附有代码。

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

If anyone need other code I am happy to provide you. 如果有人需要其他代码,我们很乐意为您提供。 I am not able to figure out why it is clashes with the background activity. 我无法弄清楚为什么它与后台活动冲突。

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

In Activity 活动中

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
            }
        });

Try it will help you out 尝试它会帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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