In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve draggable cascading card layout by Android". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to realize the draggable cascading card layout by Android".
The company's app requires a twist function, which is actually a draggable cascading card list. The principle is still implemented by a custom Recyclerview and LayoutManager.
Customizing RecyclerView is simple, it just modifies the touch event to prevent clicks from being handled outside the card.
@ Override public boolean onTouchEvent (MotionEvent e) {if (e.getY ()
< UIUtil.dip2px(TutuApplication.getInstance().getContext(),95)||e.getY()>GetHeight ()-UIUtil.dip2px (TutuApplication.getInstance (). GetContext (), 95) {if (e.getAction ()! = MotionEvent.ACTION_UP & & e.getAction ()! = MotionEvent.ACTION_MOVE) {return false;}} return super.onTouchEvent (e);}
The actual cascading effect still needs LayoutManager to achieve.
Public class SwipeCardLayoutManager extends RecyclerView.LayoutManager {Context context; int TRANS_Y_GAP; public SwipeCardLayoutManager (Context context) {TRANS_Y_GAP= (int) TypedValue.applyDimension (TypedValue.COMPLEX_UNIT_DIP,15, context.getResources (). GetDisplayMetrics ());} @ Override public RecyclerView.LayoutParams generateDefaultLayoutParams () {return new RecyclerView.LayoutParams (ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) } @ Override public void onLayoutChildren (RecyclerView.Recycler recycler, RecyclerView.State state) {super.onLayoutChildren (recycler, state); / / 1. How to realize the cascading effect-- cardView.layout (lmemt _ r _ r _ b) / / 2. How to display 4 of the 8 entries in RecylerView / / 1 before laying out the layout, detach all the sub-View, and then cache them in the Scrap collection. DetachAndScrapAttachedViews (recycler); / / 2) add only the top 4 view to the RecylerView container int itemCount=getItemCount (); / / 8 int bottomPosition; if (itemCount)
< CardConfig.MAX_SHOW_COUNT){ bottomPosition=0; }else{ bottomPosition=itemCount-CardConfig.MAX_SHOW_COUNT; } for(int i=bottomPosition;i0){ if(level0) { adapter.removeAdapterData(adapter.getItemCount() - 1);// mDatas.add(0, remove); adapter.notifyDataSetChanged(); listener.onSwipe(); if (adapter.getItemCount() == 6) { listener.onSwipeEnd(); } tv.setText(context.getResources().getString(R.string.explored) + (++x) + "/????"); } } @Override public void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); //监听话滑动的距离--控制动画的执行程度 if(dY == 0f&&!isCurrentlyActive){ int itemcount = recyclerView.getChildCount(); for (int i = 0; i < itemcount; i++) { //执行 View view = recyclerView.getChildAt(i); //几个view层叠的效果,错开的效果--便宜动画+缩放动画 int level = itemcount - i - 1; view.setRotation(0); if(dX == 0) { if(level>0) {if (level 1) {fraction = 1;} int itemcount = recyclerView.getChildCount (); for (int I = 0; I < itemcount; iTunes +) {/ / execute View view = recyclerView.getChildAt (I) / / cascading effects of several view, staggered effects-cheap animation + zoom animation int level = itemcount-I-1; if (level = = 0) {/ / outermost animation if (Math.abs (dX) = = 1080f & & dY = = 0f animation is currentlyactive) {view.setRotation (0) } else {if (dX0) {swipe ();}); at this point, I believe you have a better understanding of "how Android implements draggable cascading card layout". Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.