In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to achieve the function of the commodity details page in Android". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Let's take a look at the effect.
Due to the excessive amount of code, we will not explain one by one only a few core custom controls)
0 & & t = = 0) {getParent () .getParent () .requestDisallowInterceptTouchEvent (false);} break; case MotionEvent.ACTION_DOWN: getParent () .getParent () .requestDisallowInterceptTouchEvent (true); oldY = ev.getY (); oldX = ev.getX (); break Case MotionEvent.ACTION_UP: getParent (). GetParent (). RequestDisallowInterceptTouchEvent (true); break; default: break;} return super.onTouchEvent (ev);} @ Override protected void onScrollChanged (int l, int t, int oldl, int oldt) {this.t = t Super.onScrollChanged (l, t, oldl, oldt);}}
ItemListView is also a child View of SlideDetailsLayout.
It has about the same function as ItemWebView.
/ * ListView * / public class ItemListView extends ListView implements AbsListView.OnScrollListener {private float oldX, oldY; private int currentPosition; public ItemListView (Context context) {super (context); setOnScrollListener (this);} public ItemListView (Context context, AttributeSet attrs) {super (context, attrs); setOnScrollListener (this) at the bottom of the commodity details page } public ItemListView (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); setOnScrollListener (this);} @ Override public boolean onTouchEvent (MotionEvent ev) {switch (ev.getAction ()) {case MotionEvent.ACTION_MOVE: float Y = ev.getY (); float Ys = Y-oldY Float X = ev.getX (); int [] location = new int [2]; getLocationInWindow (location); / / Slide to the top to let the parent control regain the touch event if (Ys > 0 & & currentPosition = = 0) {getParent () .getParent () .requestDisallowInterceptTouchEvent (false) } break; case MotionEvent.ACTION_DOWN: getParent (). GetParent (). RequestDisallowInterceptTouchEvent (true); oldY = ev.getY (); oldX = ev.getX (); break; case MotionEvent.ACTION_UP: getParent (). GetParent (). RequestDisallowInterceptTouchEvent (true) Break; default: break;} return super.onTouchEvent (ev);} @ Override public void onScrollStateChanged (AbsListView view, int scrollState) {currentPosition = getFirstVisiblePosition ();} @ Override public void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}}
NoScrollViewPager is the outermost parent layout
When you slide to the picture and text details module, you can disable the sliding event of ViewPager.
/ * Custom ViewPager * / public class NoScrollViewPager extends ViewPager {private boolean noScroll = false; public NoScrollViewPager (Context context, AttributeSet attrs) {super (context, attrs);} public NoScrollViewPager (Context context) {super (context);} public void setNoScroll (boolean noScroll) {this.noScroll = noScroll } @ Override public void scrollTo (int x, int y) {super.scrollTo (x, y);} @ Override public boolean onTouchEvent (MotionEvent arg0) {if (noScroll) return false; else return super.onTouchEvent (arg0);} @ Override public boolean onInterceptTouchEvent (MotionEvent arg0) {if (noScroll) return false Else return super.onInterceptTouchEvent (arg0);} @ Override public void setCurrentItem (int item, boolean smoothScroll) {super.setCurrentItem (item, smoothScroll);} @ Override public void setCurrentItem (int item) {super.setCurrentItem (item);}}
The outermost layout of the merchandise module is a custom ViewGroup named SlideDetailsLayout
SlideDetailsLayout content has two View, mFrontView (* View) and mBehindView (second View)
There are two states. If the status is set to close, * commodity data View will be displayed, and the open status will show the second picture and text details View.
@ SuppressWarnings ("unused") public class SlideDetailsLayout extends ViewGroup {/ * * Callback for panel OPEN-CLOSE status changed. * / public interface OnSlideDetailsListener {/ * * Called after status changed. * * @ param status {@ link Status} * / void onStatucChanged (Status status);} public enum Status {/ * * Panel is closed * / CLOSE, / * * Panel is opened * / OPEN; public static Status valueOf (int stats) {if (0 = = stats) {return CLOSE } else if (1 = = stats) {return OPEN;} else {return CLOSE;} private static final float DEFAULT_PERCENT = 0.2f; private static final int DEFAULT_DURATION = 300; private View mFrontView; private View mBehindView; private float mTouchSlop; private float mInitMotionY; private float mInitMotionX Private View mTarget; private float mSlideOffset; private Status mStatus = Status.CLOSE; private boolean isFirstShowBehindView = true; private float mPercent = DEFAULT_PERCENT; private long mDuration = DEFAULT_DURATION; private int mDefaultPanel = 0; private OnSlideDetailsListener mOnSlideDetailsListener; public SlideDetailsLayout (Context context) {this (context, null);} public SlideDetailsLayout (Context context, AttributeSet attrs) {this (context, attrs, 0) } public SlideDetailsLayout (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes (attrs, R.styleable.SlideDetailsLayout, defStyleAttr, 0); mPercent = a.getFloat (R.styleable.SlideDetailsLayout_percent, DEFAULT_PERCENT); mDuration = a.getInt (R.styleable.SlideDetailsLayout_duration, DEFAULT_DURATION); mDefaultPanel = a.getInt (R.styleable.SlideDetailsLayout_default_panel, 0) This is the end of the content of "how to achieve the function of commodity details page in Android". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.