Android custom sliding viewgroup up and down, Android custom ViewGroup to achieve elastic sliding effect
Customize View to achieve an elastic sliding effect,for your reference,The specific content is as follows Implementation principle Measure all sub-Views in onMeasure() @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // Measure all child Views int count = getChildCount(); for (int i = 0; i <count; i++) { View childView = getChildAt(i); measureChild( childView, widthMeasureSpec, heightMeasureSpec); } setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); } onLayout(), will All sub-Views are arranged in order of position @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // Set the height of ViewGroup and arrange all child Views int childCount = getChildCount(); MarginLayoutParams params = ( MarginLayoutParams) getLayoutParams(); params.height = mScreenHeight * childCount; for (int i = 0; i <childCount; i+& #43;) { View childView = getChildAt(i); if (childView.getVisibility() != View.GONE) { // Place each ChildView at the specified position childView.layout(l, i * mScreenHeight, r, (i + 1) * mScreenHeight); } } } handle sliding in onTouchEvent() @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mLastY = ( int) event.getY(); mStart = getScrollY(); return true; case MotionEvent.ACTION_MOVE: if (!mScroller.isFinished()) { // Terminate sliding mScroller.abortAnimation(); } int offsetY = (int) (mLastY – event.getY()); Log.d(TAG, “onTouchEvent: getScrollY: ” + getScrollY()); Log.d(TAG, “onTouchEvent:…