如何从退出中删除闪烁显示动画并使其从触摸点显示

时间:2017-05-09 16:20:29

标签: android circularreveal

我想要实现的目标是:

  1. 当单击recyclerView中的某个项目时,详细信息活动应显示,从我的手指接触到的点开始 屏幕。

  2. 当我触摸向上箭头按钮或后退按钮时,细节活动应以圆形显示结束并停在 我的手指最初触摸了屏幕。

  3. 我的代码:

    MyRecyclerViewHolder

    private OnGridItemClickedListener itemClickedListener
    
        public MyRecyclerViewHolder(View itemView,  OnGridItemClickedListener itemClickedListener) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemClickedListener = itemClickedListener;
            rippleView.setOnTouchListener(touchListener);
        }
    
    
        private View.OnTouchListener touchListener = new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    itemClickedListener.onItemClick(getAdapterPosition(), null, (int)event.getY(), (int)event.getX());
                }
                return true;
            }
        };
    

    MyFragment

    // Removed irrelevant codes
     MyAdapter adapter = new MyAdapter(itemsList, true);
     recyclerView.setLayoutManager(new GridAutoFitLayoutManager(getActivity(), MyConvert.dpToPx(150, getActivity())));
     recyclerView.setAdapter(adapter);
     recyclerView.setHasFixedSize(true);
    
     adapter.setOnGridItemClickedListener(new OnGridItemClickedListener() {
         @Override
         public void onItemClick(int position, String stringId, int y, int x) {
             launchMyDetailsActivity(position, y, x);
         }
     });
    
     private void launchMyDetailsActivity(int index, int y, int x) {
         Intent intent = new Intent(getActivity(), MyDetailsActivity.class);
         intent.putExtra(Keys.EXTRA_Y, y);
         intent.putExtra(Keys.EXTRA_X, x);
         startActivity(intent);
     }
    

    MyDetailsActivity

    // Removed irrelevant codes
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_grid_details);
         ButterKnife.bind(this);
         setSupportActionBar(toolbar);
         getSupportActionBar().setDisplayHomeAsUpEnabled(true);
         setViewListeners();
         startEnterTransition();
     }
    
     private void startEnterTransition () {
         coordinatorLayout.post(new Runnable() {
             @Override
             public void run() {
                 int x = getIntent().getIntExtra(Keys.EXTRA_X, 0);
                 int y = getIntent().getIntExtra(Keys.EXTRA_Y, 0);
    
                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && x != 0 && y != 0) {
                     // get the final radius for the clipping circle
                     int finalRadius = Math.max(coordinatorLayout.getWidth(), coordinatorLayout.getHeight()) / 2;
    
                     // create the animator for this view (the start radius is zero)
                     Animator anim = ViewAnimationUtils.createCircularReveal(coordinatorLayout, x, y, 0, finalRadius);
    
                     // make the view visible and start the animation
                     coordinatorLayout.setVisibility(View.VISIBLE);
                     anim.start();
                 }
             }
         });
     }
    
     private void startExitTransition () {
         int x = getIntent().getIntExtra(Keys.EXTRA_X, 0);
         int y = getIntent().getIntExtra(Keys.EXTRA_Y, 0);
    
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && x != 0 && y != 0) {
             int initialRadius = coordinatorLayout.getWidth() / 2;
    
             Animator anim = ViewAnimationUtils.createCircularReveal(coordinatorLayout, x, y, initialRadius, 0);
    
             anim.addListener(new AnimatorListenerAdapter() {
                 @Override
                 public void onAnimationEnd(Animator animation) {
                     super.onAnimationEnd(animation);
                     coordinatorLayout.setVisibility(View.INVISIBLE);
                     supportFinishAfterTransition();
                 }
             });
    
             anim.start();
    
         } else {
             supportFinishAfterTransition();
         }
     }
    
     @Override
     public void onBackPressed() {
         startExitTransition();
     }
    
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
    
             case android.R.id.home:
                 startExitTransition();
                 return true;
         }
    
         return super.onOptionsItemSelected(item);
     }
    

    问题

    1. 揭幕动画从屏幕的左上角开始,即使我点击的项目接近底部,也靠近汉堡图标 的屏幕。退出动画也是如此,它停在屏幕的左上角

    2. 退出动画结束后,屏幕闪烁,并不会一直发生,但确实会发生。

    3. 已实施解决方案

      我在viewHolder中尝试了这个:itemView.getX()itemView.getY()itemView.getRight()itemView.getTop()。这些出现了    要解决上面的第一个问题,但动画的进入和退出点总是从recyclerView项目的位置开始。

      请问如何解决上面的数字和2个问题?

0 个答案:

没有答案