查看鳍状肢不会翻转

时间:2014-01-04 05:30:49

标签: android view viewflipper

我已经在SO上阅读了关于这个主题的所有三个问题,其中一个提到完全相同的问题和相同的步骤但没有解决方案(参见下文)。

我在这个SO链接中遇到与James完全相同的问题 View flipper is not flipping

我尝试了几乎相同的技巧。我确定我的观点正在翻转,但除了第一个观点外我没有看到新的图片。

在阅读以下帖子http://chat.stackoverflow.com/rooms/11715/discussion-between-james-and-sdfwer中链接的讨论之后,我相信詹姆斯和我可能犯了同样的错误,但讨论中没有提到决议。

我也读过关于SO的其他答案,谈论这个问题,但没有一个提供正确的解决方案。

有人能帮帮我吗?这是我正在使用的代码。我想要一个图像列表,每个图像由一个视图鳍状肢控制。如果要翻转图像,它将转换为带有图像名称的文本视图。

    public class CustomListViewAdapter extends ArrayAdapter<ScreenObject> {
    private static final int SWIPE_MIN_DISTANCE = 70;
    private static final int SWIPE_MAX_DISTANCE = 50;
    private static final int SWIPE_THRESHOLD_VELOCITY = 120;

    public CustomListViewAdapter(Context new_context, int resource_id,
      List<ScreenObject> items, BitmapManager new_bitmap_manager) {
      super(new_context, resource_id, items);
      bitmap_manager = new_bitmap_manager;
    }

    class SwipeGestureDetector extends SimpleOnGestureListener {
      private ScreenObjectViewFlipper view_flipper;

      SwipeGestureDetector(ScreenObjectViewFlipper flip_view) {
        view_flipper = flip_view;
      }

      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
        Context context = MainActivity.application_context;
        try {
          if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_DISTANCE)
            return false;
          // Top to bottom swipe 
          if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
                  && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            Log.i("screenshotsaver", "flig up");
            view_flipper.setInAnimation(AnimationUtils.loadAnimation(context,
                    R.anim.in_from_bottom));
            view_flipper.setOutAnimation(AnimationUtils.loadAnimation(context,
                    R.anim.out_to_top));
            // controlling animation
            view_flipper.showNext();
            return true;
          } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                  && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            Log.i("screenshotsaver", "flig down");
            view_flipper.setInAnimation(AnimationUtils.loadAnimation(context,
                    R.anim.in_from_top));
            view_flipper.setOutAnimation(AnimationUtils.loadAnimation(context,
                    R.anim.out_to_bottom));
            view_flipper.showPrevious();
            return true;
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
        return false;
      }
    }

    class ViewHolder {
      public ScreenObjectViewFlipper flip_view;
      public TextView txt_view;
      GestureDetector detector;
    }

    @Override
    public View getView(int position, View convert_view, ViewGroup parent) {
      ScreenObject screen_object = getItem(position);
      LayoutInflater inflater = (LayoutInflater) MainActivity.application_context
              .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
      ViewHolder holder = null;
      if (convert_view == null) {
        convert_view = inflater.inflate(R.layout.flip_view, null);
        holder = new ViewHolder();
        holder.flip_view = (ScreenObjectViewFlipper) convert_view
                .findViewById(R.id.view_flipper);
        holder.txt_view = (TextView) convert_view.findViewById(R.id.title);
        final GestureDetector detector = new GestureDetector(
                MainActivity.application_context,
                new SwipeGestureDetector(holder.flip_view));
        holder.flip_view.setOnTouchListener(new OnTouchListener() {
          @Override
          public boolean onTouch(final View view, final MotionEvent event) {
            detector.onTouchEvent(event);
            return true;
          }
        });
        holder.detector = detector;
        convert_view.setTag(holder);
      } else
        holder = (ViewHolder) convert_view.getTag();

      holder.txt_view.setText(screen_object.footer_text);
      holder.txt_view.setTag(screen_object.footer_url);
      return convert_view;
    }
  }

0 个答案:

没有答案