2016-09-28 16 views
0

.浮點按鈕與Android中的後臺活動衝突嗎?

問題是當我點擊浮動圖像按鈕背景佈局也是調用。

我下面也附上了代碼。

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

如果有人需要其他代碼,我很樂意爲您提供。我無法弄清楚它爲什麼會與背景活動發生衝突。

+0

添加ID到父佈局,把一個onClickListener爲同一它將解決您的問題 –

+0

手段相對佈局添加ID並onClickListener調用浮動按鈕@MohitTrivedi –

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

嘗試將幫助你

+0

沒有幫助..問題是這個浮點是開放的夜間活動也.. –

+0

你可以p租賃給我你的演示我會糾正它,如果你不介意? –

+0

對不起@Mohit –