2017-04-04 4 views
0

TranslateAnimation을 사용하면 항목을 클릭 할 때 프로필 사진을 맨 위로 이동하려고합니다.TranslateAnimation을 항목 (ListView에서)으로 사용하면 상위 항목을 가져 가지 않습니다.

올바른 위치 (x, y)를 찾았지만 프로필 사진이 항목 영역에서 나오지 않습니다.

bringToFront() 메서드를 사용하려고했지만 작동하지 않습니다.

enter image description here

내 여기에 문제

enter image description here

코드 내보기 애니메이션합니다

public void animateContactAdding(View view) { 
     View profileImage = view.findViewById(R.id.linear_layout_image_profile); 

     int positionViewContact[] = {0, 0}; 
     profileImage.getLocationOnScreen(positionViewContact); 

     int positionHeader[] = {0, 0}; 
     mRelativeLayoutContactHeader.getLocationOnScreen(positionHeader); 

     float distanceBtwViews = (positionViewContact[1] - positionHeader[1]) * -1; 

     TranslateAnimation anim = new TranslateAnimation(0, 0, 0, distanceBtwViews); 
     anim.setDuration(400); 

     anim.setAnimationListener(new TranslateAnimation.AnimationListener() { 

      @Override 
      public void onAnimationStart(Animation animation) { 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 
      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
      } 
     }); 

     profileImage.startAnimation(anim); 
    } 

항목

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight"> 

    <LinearLayout 
     android:id="@+id/linear_layout_image_profile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/circle_image_placeholder" 
      android:layout_width="?android:attr/listPreferredItemHeight" 
      android:layout_height="?android:attr/listPreferredItemHeight" 
      android:padding="10dp" /> 

     <ImageView 
      android:id="@+id/circle_image_profile" 
      android:layout_width="?android:attr/listPreferredItemHeight" 
      android:layout_height="?android:attr/listPreferredItemHeight" 
      android:padding="10dp" /> 

    </LinearLayout> 

    <TextView 
     android:id="@android:id/text2" 
     android:layout_width="match_parent" 
     android:layout_height="26dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_toEndOf="@+id/linear_layout_image_profile" 
     android:ellipsize="marquee" 
     android:lines="1" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@android:id/text1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@android:id/text2" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignWithParentIfMissing="true" 
     android:layout_toEndOf="@+id/linear_layout_image_profile" 
     android:ellipsize="marquee" 
     android:gravity="center_vertical" 
     android:lines="1" 
     android:textAppearance="@style/TextAppearance.RalewaySemiBold" 
     android:textSize="17sp" /> 

</RelativeLayout> 

답변

0

아마도 전체 레이아웃에 애니메이션을 적용하고있을 것입니다. 내 코드는 이미이 일을

public void animateContactAdding(View view) { 
     int positionViewContact[] = {0, 0}; 
     profileImage.getLocationOnScreen(positionViewContact); 

     int positionHeader[] = {0, 0}; 
     mRelativeLayoutContactHeader.getLocationOnScreen(positionHeader); 

     float distanceBtwViews = (positionViewContact[1] - positionHeader[1]) * -1; 

     TranslateAnimation anim = new TranslateAnimation(
      Animation.RELATIVE_TO_SELF, 0.0F, Animation.RELATIVE_TO_SELF, 0.0F, 
      Animation.RELATIVE_TO_SELF, 2.0F, Animation.RELATIVE_TO_SELF, 0.0F 
    ); 
     anim.setDuration(2000); 
     anim.setFillAfter(true); 
     anim.setAnimationListener(new TranslateAnimation.AnimationListener() { 

      @Override 
      public void onAnimationStart(Animation animation) { 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { 
      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
      } 
     }); 

     view.startAnimation(anim); 
    } 
+0

: 만 ImageView에 애니메이션을 적용하고 어떻게되는지보십시오. 나는 텍스트없이 그냥 프로필 그림을 움직이고있다. – Johnny

+0

레이아웃에 애니메이션을 적용하고 있습니까? 이 줄을보세요 : profileImage = view.findViewById (R.id.linear_layout_image_profile); –

+0

오, 오케이. 네, 내 항목은 두 개의'ImageView'를 포함하고있는'LinearLayout'을 포함하고 있습니다. 나는 ImageView에서 직접 시도해 보았지만 똑같은 것처럼 보였다. -/ – Johnny