android - LinearLayout onclick does not translate after TranslateAnimation -


here problem. have linearlayout has clickable=true ontouch event when linearlayout touched, slides screen. works, afterward when ontouch event fired new location nothing happens.

steps:

  1. i touch linearlayout , moves should.
  2. i touch again , nothing happens
  3. i touch part of screen linearlayout linearlayout toggle should.

it appears if view has moved new location in reality has not.

below xml & code.

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"               android:id="@+id/julycontainer"               android:orientation="vertical"               android:layout_width="fill_parent"               android:layout_height="fill_parent">           <relativelayout android:id="@+id/rel01"/>          <imageview />         </relativelayout>          <imageview                          android:id="@+id/shadow"             android:paddingtop="6dip"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="@drawable/header_barshadow"/>  <scrollview      android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical"     android:background="@drawable/bg_calendar"      android:id="@+id/calscroller">   <relativelayout          android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical">                  <linearlayout android:id="@+id/circlelayout"                 android:orientation="horizontal"                 android:clickable="true"                 android:onclick="@string/circleaction"                               android:paddingtop="10dip"                 android:paddingleft="10dip"                 android:layout_width="match_parent"                 android:layout_height="wrap_content">                  <button                  android:id="@+id/circlecal"                 android:background="@drawable/cal_circle_button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:onclick="@string/circleaction"/>                  <linearlayout                  android:id="@+id/circlelayout01"                 android:orientation="vertical"                     android:paddingleft="10dip"             android:paddingright="3dip"                 android:layout_width="match_parent"                 android:layout_height="wrap_content">                  <textview/>                   <textview/>                   <textview/>                   <linearlayout android:id="@+id/julylayout2"                     android:layout_width="match_parent"                     android:layout_height="0dp"                     android:orientation="vertical">                <textview/>                 </linearlayout>              </linearlayout>         </linearlayout>         <imageview android:id="@+id/etch1"                   android:src="@drawable/etch_calendar"                   android:paddingtop="15dip"                   android:paddingbottom="15dip"                   android:layout_width="wrap_content"                   android:layout_height="wrap_content"                   android:layout_below="@id/circlelayout"/>                             <linearlayout android:id="@+id/squarelayout"                 android:clickable="true"                 android:onclick="@string/squareaction"                               android:orientation="horizontal"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:paddingleft="10dip"                 android:layout_below="@id/etch1">         <button                  android:id="@+id/squarecal"                 android:background="@drawable/cal_square_button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:onclick="@string/squareaction"/>                  <linearlayout             android:orientation="vertical"             android:paddingleft="10dip"             android:paddingright="3dip"             android:layout_width="match_parent"             android:layout_height="wrap_content">                  <textview/>                   <textview/>                   <textview/>                  <linearlayout android:id="@+id/layout3"                     android:layout_width="match_parent"                     android:layout_height="0dp"                     android:orientation="vertical">                      <textview/>                   </linearlayout>         </linearlayout>             </linearlayout>          </relativelayout> </scrollview>       </linearlayout>   

code:

private void slideup(view view) {     animation slide = new translateanimation(             animation.relative_to_self, 0.0f, animation.relative_to_self,             0.0f, animation.relative_to_self, 0.0f, animation.relative_to_self, -0.25f);     slide.setduration(1000);     slide.setfillafter(true);     slide.setfillenabled(true);      view.startanimation(slide); }  private void slidedown(view view) {     animation slide = new translateanimation(             animation.relative_to_self, 0.0f, animation.relative_to_self,             0.0f, animation.relative_to_self, -0.25f, animation.relative_to_self, 0.0f);     slide.setduration(1000);     slide.setfillafter(true);     slide.setfillenabled(true);     view.startanimation(slide); } 

new changes: output of new positions

07-05 13:20:22.084: i/system.out(15187): onanimationstart 0 , 120

07-05 13:20:23.053: i/system.out(15187): onanimationend 0 , 120

private void slideup(final view view) {          animation slide = new translateanimation(                 animation.relative_to_self, 0.0f, animation.relative_to_self,                 0.0f, animation.relative_to_self, 0.0f, animation.relative_to_self, -0.75f);         slide.setduration(1000);         slide.setfillafter(true);         slide.setfillenabled(true);         view.startanimation(slide);         slide.setanimationlistener(new animationlistener() {              @override             public void onanimationstart(animation animation) {                 int[] startposition = new int[2];                 view.getlocationonscreen(startposition);                 system.out.println("onanimationstart " + startposition[0] + " , " + startposition[1]);             }              @override             public void onanimationrepeat(animation animation) {             }              @override             public void onanimationend(animation animation) {                 final int left = view.getleft();                 final int top = view.gettop();                 final int right = view.getright();                 final int bottom = view.getbottom();                  int offset = (int) 0.75;                 view.layout(left, top + offset * top, right, bottom + offset * bottom);                  int[] endposition = new int[2];                 view.getlocationonscreen(endposition);                 system.out.println("onanimationend " + endposition[0] + " , " + endposition[1]);              }          });       } 

this normal behaviour android animation. happening because animation not moves layout it's position on display remains same. if want relocate layout place animation ends, need call yourlayout.layout() method , pass there 4 parameters, describe layout's new position. keep in mind layout() gets params relative it's parent.

see sample code below

private animationlistener slidedownanimationlistener = new animationlistener() {         @override         public void onanimationstart(animation animation) {         }          @override         public void onanimationrepeat(animation animation) {         }          @override         public void onanimationend(animation animation) {             final int left = view.getleft();             final int top = view.gettop();             final int right = view.getright();             final int bottom = view.getbottom();             view.layout(left, top - 0.25 * top, right, bottom - 0.25 * bottom);         } };  private animation slidedownanimation = new translateanimation(                                      animation.relative_to_self, 0.0f,                                      animation.relative_to_self, 0.0f,                                      animation.relative_to_self, -0.25f,                                      animation.relative_to_self, 0.0f                                      );  private void slidedown(final view view) {     slide.setduration(1000);     slide.setfillafter(true);     slide.setfillenabled(true);     slide.setanimationlistener(slidedownanimationlistener);     view.startanimation(slidedownanimation); } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -