android detect when view is over another view -


i have layout:

enter image description here

what want when move view of detect if view on view and, if so, call swap method.

i want when on over half of second view in example:

enter image description here

all code complete, want detect when view on half view right or left. xml code:

<relativelayout     android:id="@+id/mmmm"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:animatelayoutchanges="false"     android:layout_gravity="center">                 <!-- first view -->              <relativelayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:layout_alignparenttop="true"                 android:layout_alignparentright="true">                  <customfonts.roundedimageview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:src="@drawable/pro2"                     android:layout_alignparentstart="false" />                  <customfonts.mytextview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:background="@drawable/circulo"                     android:text="1"                     android:gravity="center_vertical|center_horizontal"                    />             </relativelayout>              <!-- end first view -->              <!-- second view -->              <relativelayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:layout_alignparenttop="true"                 android:layout_alignparentright="true">                  <customfonts.roundedimageview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:src="@drawable/pro2"                     android:layout_alignparentstart="false" />                  <customfonts.mytextview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:background="@drawable/circulo"                     android:text="1"                     android:gravity="center_vertical|center_horizontal"                    />             </relativelayout>              <!-- end secondview -->              <!--  third view -->             <relativelayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                 android:layout_alignparenttop="true"                 android:layout_alignparentright="true">                  <customfonts.roundedimageview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:src="@drawable/pro2"                     android:layout_alignparentstart="false" />                  <customfonts.mytextview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:background="@drawable/circulo"                     android:text="1"                     android:gravity="center_vertical|center_horizontal"                    />             </relativelayout>              <!-- end third view -->          </relativelayout> 

what try

          float x1 = v.getx();           float w1 = v.getwidth();              float x2 = m.getview().getx();           float w2 = m.getview().getwidth();           if((x1+w1 >= x2 &&  x2 > x1)  || (x1 >= (x2 + w2/2) && (x2 + w2) > x1)){         log.d("overlay now","index "+m.getindex());          } 

this code try don't know problem of , it's give wrong x , position


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -