빌드 갤러리처럼 센터 이미지를 확대하는 갤러리를 구현하고 싶습니다. 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에서는 작동하지 않습니다. 모든 이미지 항목의 크기가 같습니다. 여기에 실수가 있습니까? 이 문제를 해결하도록 도와주세요.
감사합니다.
나는 해결책을 시도했지만 완벽하게 작동하지 않습니다. 이미지는 확대되지만 크기는 변경되지 않습니다. 경계 안의 줌입니다. –