0

ビルトインギャラリーのように中央の画像を拡大するギャラリーを実装したいです。リスナーにonItemSelectedスケール アニメーションをロードして、中央の画像を大きくします。これが私のコードです:

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>

Android 2.x ではすべて問題ありませんが、Android 4.x では機能しません。すべての画像アイテムは同じサイズです。ここに間違いはありますか?これを解決するのを手伝ってください。

ありがとう。

4

2 に答える 2

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();
    }

GridViewアイテムが s であるアイテムのアニメーションを設定しようとしているときに、ほぼ同じ問題が発生ImageViewしました。このトリックは、Android 2+ と 4+ の両方で機能しました。使用したいビューのインスタンスを取得し、アニメーションを再生するだけです。あなたの状況では次のようになるはずです

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

これimageをアニメーションに使用します。

これがうまくいくことを願っています!: )

于 2013-10-21T10:08:39.810 に答える
0

そのようにするべきではありません。より簡単な方法は、ViewGroup.getChildStaticTransformation メソッドをオーバーライドすることです。その方法で、アイテムを完全に制御できます。または、ViewGroup.drawChild の方が優れていますが、後者は使用するのがはるかに困難です。

于 2013-10-21T10:32:12.933 に答える