索引zeio中的Gridview单元格没有翻转

时间:2014-12-18 18:26:23

标签: android animation gridview viewflipper

您好我有奇怪的问题,我正在使用Gridview,单击时单元格应该翻转,所有单元格都会翻转,但索引为零的单元格不会翻转! 3D翻转库是this 单元格的代码是

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#ffffff" >

<ViewFlipper
    android:id="@+id/viewFlipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:layout_gravity="center"
    android:addStatesFromChildren="true"
    android:background="#ffffff"
    android:clickable="true"
    android:gravity="center" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#ffffff"
        android:clickable="true" />

    <LinearLayout
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="top"
        android:clickable="true"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/playpause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="40dp"
            android:src="@drawable/playbtn" />

        <ImageView
            android:id="@+id/assignwebservice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="30dp"
            android:layout_marginTop="10dp"
            android:src="@drawable/downloadicon" />
    </LinearLayout>
</ViewFlipper>

<View
    android:id="@+id/dimmedView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:alpha="0.5"
    android:background="@android:color/black" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/viewFlipper"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="48dp"
    android:layout_marginLeft="2dp"
    android:ellipsize="marquee"
    android:gravity="left"
    android:lines="1"
    android:maxLines="1"
    android:textColor="#ffffff"
    android:textSize="16sp" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignTop="@+id/textView1"
    android:layout_marginLeft="2dp"
    android:layout_marginTop="20dp"
    android:gravity="left"
    android:text="singer"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#ffffff"
    android:textSize="12sp" />

    </FrameLayout>     

和数组适配器代码

public class GridViewNewAdapter extends ArrayAdapter<mainOBj> {
ArrayList<mainOBj> mainARR;
boolean[] isFlipped = null;
ImageLoader imageLoader;
private Activity activity;
Rect rect;
Drawable background;
ImageView[] images;
LinearLayout[] flippers;
ViewAnimator viewIt;

public GridViewNewAdapter(Context context, int resource, List<mainOBj> objects) {
    super(context, resource, objects);

    mainARR = (ArrayList<mainOBj>) objects;
    activity = (Activity) context;
    imageLoader = ImageLoader.getInstance();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            context).build();
    imageLoader.init(config);

    isFlipped = new boolean[mainARR.size()];
    flippers = new LinearLayout[mainARR.size()];
    images = new ImageView[mainARR.size()];
    setNotifyOnChange(true);
    for (int i = 0; i < mainARR.size(); i++)
        isFlipped[i] = false;

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return mainARR.size();
}

static class ViewHolder {
    LinearLayout backView;
    ImageView playOrPause;
    ImageView thumb;
    TextView title;
    TextView singer;
    View dimmedView;
    ViewAnimator viewAnim;
    ImageView assign;
    int position;
}

@Override
public View getView(final int position, View convertView,
        final ViewGroup parent) {
    // TODO Auto-generated method stub
    // ViewHolder view;
    final LayoutInflater inflator = activity.getLayoutInflater();
    final ViewHolder viewHolder;

    if (convertView == null) {
        convertView = inflator.inflate(R.layout.gridview_row, null);

        viewHolder = new ViewHolder();
        viewHolder.backView = ((LinearLayout) convertView
                .findViewById(R.id.imageView1));
        viewHolder.thumb = ((ImageView) convertView
                .findViewById(R.id.imageView2));
        viewHolder.title = ((TextView) convertView
                .findViewById(R.id.textView1));
        viewHolder.playOrPause = ((ImageView) convertView
                .findViewById(R.id.playpause));
        viewHolder.viewAnim = (ViewAnimator) convertView
                .findViewById(R.id.viewFlipper);
        viewHolder.singer = (TextView) convertView
                .findViewById(R.id.textView2);
        viewHolder.dimmedView = convertView.findViewById(R.id.dimmedView);
        viewHolder.assign = (ImageView) convertView
                .findViewById(R.id.assignwebservice);
        viewHolder.position = position;
        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    final View dimmedView = viewHolder.dimmedView;

    if (mainARR.get(position).getThumbnail() != null) {
        String thumbURL = mainARR.get(position).getThumbnail();
        final ImageView im = viewHolder.thumb;

        imageLoader.displayImage(thumbURL, im, new ImageLoadingListener() {

            @Override
            public void onLoadingStarted(String arg0, View arg1) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onLoadingFailed(String arg0, View arg1,
                    FailReason arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onLoadingComplete(String arg0, View arg1,
                    Bitmap arg2) {
                // TODO Auto-generated method stub
                im.setScaleType(ImageView.ScaleType.FIT_XY);
            }

            @Override
            public void onLoadingCancelled(String arg0, View arg1) {
                // TODO Auto-generated method stub

            }
        });

    }

    flippers[position] = viewHolder.backView;
    flippers[position].setTag(viewHolder.position);
    final TextView title = viewHolder.title;
    title.setText(mainARR.get(position).getTitle());
    final TextView singerName = viewHolder.singer;
    // final View dimmedView = convertView.findViewById(R.id.dimmedView);
    String singer = mainARR.get(position).getSinger();
    singerName.setText(singer);

    images[position] = viewHolder.playOrPause;
    images[position].setTag(position);


    final ViewAnimator viewAnimator = viewHolder.viewAnim;
    if (position == 0)
        viewIt = viewAnimator;
    viewHolder.viewAnim.setTag(position);

    viewAnimator.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AnimationFactory.flipTransition(viewAnimator,
                    FlipDirection.LEFT_RIGHT);

        }

    });

    flippers[position].setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            isFlipped[(Integer) v.getTag()] = false;
            AnimationFactory.flipTransition(viewAnimator,
                    FlipDirection.LEFT_RIGHT);
            Animation fadeInAnimation = AnimationUtils.loadAnimation(
                    activity, R.anim.fadein_anim);

            // Now Set your animation
            title.startAnimation(fadeInAnimation);
            // title.setVisibility(View.VISIBLE);
            singerName.startAnimation(fadeInAnimation);

            // singerName.setVisibility(View.VISIBLE);

            dimmedView.setBackgroundColor(Color.BLACK);
            // dimmedView.setVisibility(View.VISIBLE);
            dimmedView.startAnimation(fadeInAnimation);

            fadeInAnimation.setAnimationListener(new AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    // TODO Auto-generated method stub
                    title.setVisibility(View.VISIBLE);
                    dimmedView.setVisibility(View.VISIBLE);
                    singerName.setVisibility(View.VISIBLE);
                }
            });
        }

    });
    viewHolder.assign.setTag(position);
    viewHolder.thumb.setTag(position);

    viewHolder.thumb.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            // int i = 0;
            for (int i = 0; i < getCount(); i++) {
                if (isFlipped[i]) {
                    final int k = i;
                    flippers[k].post(new Runnable() {
                        @Override
                        public void run() {
                            // TODO Auto-generated method stub
                            flippers[k].performClick();
                            if (k == 0) {
                                flippers[k].performClick();
                            }
                        }
                    });

                }
            }

            int x = (Integer) v.getTag();
            isFlipped[x] = true;
            AnimationFactory.flipTransition(viewAnimator,
                    FlipDirection.LEFT_RIGHT);

            title.setVisibility(View.GONE);
            singerName.setVisibility(View.GONE);
            dimmedView.setVisibility(View.GONE);

        }

    });

    return convertView;
}}

0 个答案:

没有答案