2013-10-21 6 views
0

빌드 갤러리처럼 센터 이미지를 확대하는 갤러리를 구현하고 싶습니다. onItemSelected 리스너에 센터 이미지를 크게 만들기 위해 스케일 애니메이션을로드합니다. 여기 내 코드입니다 :애니메이션이 안드로이드 4.x에서 작동하지 않습니다

joinedProgramImages = new int[] { R.drawable.temp_lotteria_logo, R.drawable.temp_starbucks_logo, R.drawable.temp_cocacola_logo,R.drawable.temp_lotteria_logo, R.drawable.temp_starbucks_logo }; 
     JoinedProgramsAdapter adapter = new JoinedProgramsAdapter(); 
     galleryJoinedPrograms.setAdapter(adapter); 
     galleryJoinedPrograms.setSpacing(-20); 
     galleryJoinedPrograms.setSelection(1); 
     galleryJoinedPrograms.setHorizontalFadingEdgeEnabled(true); 
     galleryJoinedPrograms.setOnItemSelectedListener(new OnItemSelectedListener() { 

     @Override 
     public void onItemSelected(AdapterView<?> viewgroup, View view, int position, long arg3) { 
      //zoom out previous center image. 
      if (selectedProgram != null) { 
       Animation animation = (Animation) AnimationUtils.loadAnimation(getApplicationContext(), R.animator.statelist_zoomout_gallery_image); 
       selectedProgram.startAnimation(animation); 
       animation.startNow(); 
      } 
      //zoom in the center image. 
      Animation animation = (Animation) AnimationUtils.loadAnimation(getApplicationContext(), R.animator.statelist_zoomin_gallery_image); 
      view.startAnimation(animation); 
      selectedProgram = view; 
      animation.startNow(); 
     } 

     @Override 
     public void onNothingSelected(AdapterView<?> arg0) { 

     } 
    }); 

갤러리의 어댑터 :

private class JoinedProgramsAdapter extends BaseAdapter { 

     @Override 
     public int getCount() { 
      return joinedProgramImages.length; 
     } 

     @Override 
     public Object getItem(int position) { 
      return joinedProgramImages[position]; 
     } 

     @Override 
     public long getItemId(int position) { 
      return 0; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      if (convertView == null) { 
       convertView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.view_joinedprogram_item, null); 
      } 
      ImageView img = (ImageView) convertView.findViewById(R.id.view_joinedPrograms_imageview_thumbnail); 
      img.setImageResource(joinedProgramImages[position]); 
      return convertView; 
     } 

    } 

갤러리 이미지 항목 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 


    <ImageView 
     android:id="@+id/view_joinedPrograms_imageview_thumbnail" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_horizontal" 
     android:background="@drawable/temp_lotteria_logo" /> 


</LinearLayout> 

애니메이션에서 줌 :

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" 
    android:fillAfter="true" 
> 
<scale 
     android:fromXScale="1.0" 
     android:toXScale="3.50" 
     android:fromYScale="1.0" 
     android:toYScale="1.50" 
     android:duration="200" 
     android:pivotX="50%p" 
     android:pivotY="50%p" 
     android:fillAfter="true"/> 

</set> 

하고, 축소 애니메이션 :

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" 
    android:fillAfter="true" 
> 
<scale 
     android:fromXScale="1.5" 
     android:toXScale="1.0" 
     android:fromYScale="1.5" 
     android:toYScale="1.0" 
     android:duration="200" 
     android:pivotX="50%p" 
     android:pivotY="50%p" 
     android:fillAfter="true"/> 

</set> 

안드로이드 2.x에서는 모든 것이 정상이지만 안드로이드 4.x에서는 작동하지 않습니다. 모든 이미지 항목의 크기가 같습니다. 여기에 실수가 있습니까? 이 문제를 해결하도록 도와주세요.

감사합니다.

답변

2

이 비슷한을 사용해보십시오 :

@Override 
    public void onItemSelected(AdapterView<?> viewgroup, View view, int position, long arg3) { 
     //zoom out previous center image. 
     if (selectedProgram != null) { 
      Animation animation = (Animation) AnimationUtils.loadAnimation(getApplicationContext(), R.animator.statelist_zoomout_gallery_image); 
      selectedProgram.startAnimation(animation); 
      animation.startNow(); 
     } 
     //zoom in the center image. 
     Animation animation = (Animation) AnimationUtils.loadAnimation(getApplicationContext(), R.animator.statelist_zoomin_gallery_image); 
     ImageView image = (ImageView) view.findViewById(R.id.view_joinedPrograms_imageview_thumbnail); 
     image.startAnimation(animation); 
     //animation.startNow(); 
    } 
항목이 ImageView들이었고,이 트릭은 모두 안드로이드에 나를 위해 일한 GridView 항목의 애니메이션을 설정하는 동안 나는 거의 동일한 문제가 있었다

2+ 4+. 그냥 당신이 내가 뭔가 같은

ImageView image = (ImageView) view.findViewById(R.id.view_joinedPrograms_imageview_thumbnail); 

하고 애니메이션이 image를 사용해야합니다 상황에서 추측으로 사용하고 애니메이션을 재생하려는 뷰의 인스턴스를 얻을.

희망이 당신을 위해! :)

+0

나는 해결책을 시도했지만 완벽하게 작동하지 않습니다. 이미지는 확대되지만 크기는 변경되지 않습니다. 경계 안의 줌입니다. –

0

그런 식으로하면 안된다. ViewGroup.getChildStaticTransformation 메서드를 재정의하는 것이 더 쉬운 방법이다.이 방법으로 항목이나 ViewGroup.drawChild에 대한 모든 권한을 가지지 만 후자는 사용하기가 훨씬 어렵다.

관련 문제