├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── wzy │ │ └── nesteddetail │ │ ├── activity │ │ └── MainActivity.java │ │ ├── adapter │ │ └── RvAdapter.java │ │ ├── model │ │ └── InfoBean.java │ │ ├── utils │ │ └── DimenHelper.java │ │ └── view │ │ ├── NestedScrollingDetailContainer.java │ │ └── NestedScrollingWebView.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── layout │ ├── activity_main.xml │ ├── layout_content_layout.xml │ └── layout_title_layout.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot └── screenshot.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/* 5 | /.idea/caches 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | /.idea/navEditor.xml 10 | /.idea/assetWizardSettings.xml 11 | .DS_Store 12 | /build 13 | /captures 14 | .externalNativeBuild 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [https://segmentfault.com/a/1190000019272870](https://segmentfault.com/a/1190000019272870) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | dataBinding { 5 | enabled = true 6 | } 7 | compileSdkVersion 28 8 | defaultConfig { 9 | applicationId "com.wzy.nesteddetail" 10 | minSdkVersion 14 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation 'com.android.support:appcompat-v7:28.0.0' 26 | implementation 'com.android.support:support-v4:28.0.0' 27 | implementation 'com.android.support:recyclerview-v7:28.0.0' 28 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 29 | } 30 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.activity; 2 | 3 | import android.databinding.DataBindingUtil; 4 | import android.graphics.Color; 5 | import android.os.Build; 6 | import android.os.Bundle; 7 | import android.support.v7.app.ActionBar; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.util.TypedValue; 11 | import android.view.View; 12 | import android.webkit.WebChromeClient; 13 | import android.webkit.WebViewClient; 14 | 15 | import com.wzy.nesteddetail.R; 16 | import com.wzy.nesteddetail.adapter.RvAdapter; 17 | import com.wzy.nesteddetail.databinding.ActivityMainBinding; 18 | import com.wzy.nesteddetail.model.InfoBean; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | private ActivityMainBinding mainBinding; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main); 30 | initImmersed(); 31 | initView(); 32 | } 33 | 34 | private void initImmersed() { 35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 36 | View decorView = getWindow().getDecorView(); 37 | int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE 38 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 39 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 40 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 41 | | View.SYSTEM_UI_FLAG_FULLSCREEN 42 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; 43 | decorView.setSystemUiVisibility(option); 44 | getWindow().setNavigationBarColor(Color.TRANSPARENT); 45 | getWindow().setStatusBarColor(Color.TRANSPARENT); 46 | ActionBar actionBar = getSupportActionBar(); 47 | actionBar.hide(); 48 | } 49 | } 50 | 51 | private void initView() { 52 | initWebView(); 53 | initRecyclerView(); 54 | initToolBarView(); 55 | } 56 | 57 | private void initToolBarView() { 58 | mainBinding.vToolBar.setOnClickListener(new View.OnClickListener() { 59 | @Override 60 | public void onClick(View v) { 61 | mainBinding.nestedContainer.scrollToTarget(mainBinding.rvList); 62 | } 63 | }); 64 | } 65 | 66 | private void initWebView() { 67 | mainBinding.webContainer.getSettings().setJavaScriptEnabled(true); 68 | mainBinding.webContainer.setWebViewClient(new WebViewClient()); 69 | mainBinding.webContainer.setWebChromeClient(new WebChromeClient()); 70 | mainBinding.webContainer.loadUrl("https://github.com/wangzhengyi/Android-NestedDetail"); 71 | if (false) { 72 | // 测试JS通知内容高度回调 73 | mainBinding.webContainer.post(new Runnable() { 74 | @Override 75 | public void run() { 76 | int contentHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics()); 77 | mainBinding.webContainer.setJsCallWebViewContentHeight(contentHeight); 78 | } 79 | }); 80 | } 81 | } 82 | 83 | private void initRecyclerView() { 84 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 85 | mainBinding.rvList.setLayoutManager(layoutManager); 86 | List data = getCommentData(); 87 | RvAdapter rvAdapter = new RvAdapter(this, data); 88 | mainBinding.rvList.setAdapter(rvAdapter); 89 | } 90 | 91 | private List getCommentData() { 92 | List commentList = new ArrayList<>(); 93 | InfoBean titleBean = new InfoBean(); 94 | titleBean.type = InfoBean.TYPE_TITLE; 95 | titleBean.title = "评论列表"; 96 | commentList.add(titleBean); 97 | for (int i = 0; i < 40; i++) { 98 | InfoBean contentBean = new InfoBean(); 99 | contentBean.type = InfoBean.TYPE_ITEM; 100 | contentBean.title = "评论标题" + i; 101 | contentBean.content = "评论内容" + i; 102 | commentList.add(contentBean); 103 | } 104 | return commentList; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/adapter/RvAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.wzy.nesteddetail.R; 12 | import com.wzy.nesteddetail.model.InfoBean; 13 | 14 | import java.util.List; 15 | 16 | public class RvAdapter extends RecyclerView.Adapter { 17 | private List mData; 18 | private LayoutInflater mInflater; 19 | 20 | public RvAdapter(Context context, List datas) { 21 | this.mData = datas; 22 | this.mInflater = LayoutInflater.from(context); 23 | } 24 | 25 | @NonNull 26 | @Override 27 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) { 28 | switch (viewType) { 29 | case InfoBean.TYPE_ITEM: 30 | return new ContentHolder(mInflater.inflate(R.layout.layout_content_layout, viewGroup, false)); 31 | case InfoBean.TYPE_TITLE: 32 | return new TitleHolder(mInflater.inflate(R.layout.layout_title_layout, viewGroup, false)); 33 | default: 34 | return null; 35 | } 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) { 40 | InfoBean infoBean = mData.get(i); 41 | int viewType = getItemViewType(i); 42 | 43 | switch (viewType) { 44 | case InfoBean.TYPE_ITEM: 45 | ContentHolder contentHolder = (ContentHolder) viewHolder; 46 | contentHolder.tvTitle.setText(infoBean.title); 47 | contentHolder.tvContent.setText(infoBean.content); 48 | break; 49 | case InfoBean.TYPE_TITLE: 50 | TitleHolder titleHolder = (TitleHolder) viewHolder; 51 | titleHolder.tvTitle.setText(infoBean.title); 52 | break; 53 | } 54 | } 55 | 56 | @Override 57 | public int getItemCount() { 58 | return mData == null ? 0 : mData.size(); 59 | } 60 | 61 | @Override 62 | public int getItemViewType(int position) { 63 | return mData.get(position).type; 64 | } 65 | 66 | public static class TitleHolder extends RecyclerView.ViewHolder { 67 | TextView tvTitle; 68 | 69 | TitleHolder(@NonNull View itemView) { 70 | super(itemView); 71 | tvTitle = itemView.findViewById(R.id.tv_title); 72 | } 73 | } 74 | 75 | public static class ContentHolder extends RecyclerView.ViewHolder { 76 | TextView tvTitle; 77 | TextView tvContent; 78 | 79 | ContentHolder(@NonNull View itemView) { 80 | super(itemView); 81 | tvTitle = itemView.findViewById(R.id.tv_title); 82 | tvContent = itemView.findViewById(R.id.tv_content); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/model/InfoBean.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.model; 2 | 3 | public class InfoBean { 4 | public static final int TYPE_TITLE = 1; 5 | public static final int TYPE_ITEM = 2; 6 | 7 | public int type; 8 | public String title; 9 | public String content; 10 | 11 | @Override 12 | public String toString() { 13 | return "InfoBean{" + 14 | "type=" + type + 15 | ", title='" + title + '\'' + 16 | ", content='" + content + '\'' + 17 | '}'; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/utils/DimenHelper.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.utils; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | 6 | public class DimenHelper { 7 | public static final int NOT_CHANGE = -100; 8 | 9 | public static void updateLayout(View view, int w, int h) { 10 | if (view == null) { 11 | return; 12 | } 13 | 14 | ViewGroup.LayoutParams params = view.getLayoutParams(); 15 | if (params == null) { 16 | return; 17 | } 18 | 19 | boolean changed = false; 20 | if (w != NOT_CHANGE && params.width != w) { 21 | changed = true; 22 | params.width = w; 23 | } 24 | if (h != NOT_CHANGE && params.height != h) { 25 | changed = true; 26 | params.height = h; 27 | } 28 | 29 | if (changed) { 30 | view.setLayoutParams(params); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/view/NestedScrollingDetailContainer.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.view; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.view.NestedScrollingParent2; 7 | import android.support.v4.view.NestedScrollingParentHelper; 8 | import android.support.v4.view.ViewCompat; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.util.AttributeSet; 12 | import android.view.MotionEvent; 13 | import android.view.VelocityTracker; 14 | import android.view.View; 15 | import android.view.ViewConfiguration; 16 | import android.view.ViewGroup; 17 | import android.view.ViewParent; 18 | import android.widget.Scroller; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | public class NestedScrollingDetailContainer extends ViewGroup implements NestedScrollingParent2 { 24 | public static final String TAG_NESTED_SCROLL_WEBVIEW = "nested_scroll_webview"; 25 | public static final String TAG_NESTED_SCROLL_RECYCLERVIEW = "nested_scroll_recyclerview"; 26 | 27 | private static final int FLYING_FROM_WEBVIEW_TO_PARENT = 0; 28 | private static final int FLYING_FROM_PARENT_TO_WEBVIEW = 1; 29 | private static final int FLYING_FROM_RVLIST_TO_PARENT = 2; 30 | 31 | private boolean mIsSetFlying; 32 | private boolean mIsRvFlyingDown; 33 | private boolean mIsBeingDragged; 34 | 35 | private int mMaximumVelocity; 36 | private int mCurFlyingType; 37 | private int mInnerScrollHeight; // 容器的最大滑动距离 38 | private final int TOUCH_SLOP; 39 | private int mScreenWidth; 40 | private int mLastY; 41 | private int mLastMotionY; 42 | 43 | private NestedScrollingWebView mChildWebView; 44 | private RecyclerView mChildRecyclerView; 45 | 46 | private NestedScrollingParentHelper mParentHelper; 47 | private Scroller mScroller; 48 | private VelocityTracker mVelocityTracker; 49 | 50 | public NestedScrollingDetailContainer(Context context) { 51 | this(context, null); 52 | } 53 | 54 | public NestedScrollingDetailContainer(Context context, AttributeSet attrs) { 55 | this(context, attrs, 0); 56 | } 57 | 58 | public NestedScrollingDetailContainer(Context context, AttributeSet attrs, int defStyleAttr) { 59 | super(context, attrs, defStyleAttr); 60 | mParentHelper = new NestedScrollingParentHelper(this); 61 | mScroller = new Scroller(getContext()); 62 | ViewConfiguration viewConfiguration = ViewConfiguration.get(getContext()); 63 | mMaximumVelocity = viewConfiguration.getScaledMaximumFlingVelocity(); 64 | TOUCH_SLOP = viewConfiguration.getScaledTouchSlop(); 65 | mScreenWidth = getResources().getDisplayMetrics().widthPixels; 66 | } 67 | 68 | @Override 69 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 70 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 71 | 72 | int width; 73 | int widthMode = MeasureSpec.getMode(widthMeasureSpec); 74 | int measureWidth = MeasureSpec.getSize(widthMeasureSpec); 75 | 76 | int measureHeight = MeasureSpec.getSize(heightMeasureSpec); 77 | if (widthMode == MeasureSpec.EXACTLY) { 78 | width = measureWidth; 79 | } else { 80 | width = mScreenWidth; 81 | } 82 | 83 | int left = getPaddingLeft(); 84 | int right = getPaddingRight(); 85 | int top = getPaddingTop(); 86 | int bottom = getPaddingBottom(); 87 | int count = getChildCount(); 88 | for (int i = 0; i < count; i++) { 89 | View child = getChildAt(i); 90 | LayoutParams params = child.getLayoutParams(); 91 | int childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, left + right, params.width); 92 | int childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, top + bottom, params.height); 93 | measureChild(child, childWidthMeasureSpec, childHeightMeasureSpec); 94 | } 95 | setMeasuredDimension(width, measureHeight); 96 | findWebView(this); 97 | findRecyclerView(this); 98 | } 99 | 100 | @Override 101 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 102 | int childTotalHeight = 0; 103 | mInnerScrollHeight = 0; 104 | for (int i = 0; i < getChildCount(); i++) { 105 | View child = getChildAt(i); 106 | int childWidth = child.getMeasuredWidth(); 107 | int childHeight = child.getMeasuredHeight(); 108 | child.layout(0, childTotalHeight, childWidth, childHeight + childTotalHeight); 109 | childTotalHeight += childHeight; 110 | mInnerScrollHeight += childHeight; 111 | } 112 | mInnerScrollHeight -= getMeasuredHeight(); 113 | } 114 | 115 | @Override 116 | public boolean dispatchTouchEvent(MotionEvent ev) { 117 | int pointCount = ev.getPointerCount(); 118 | if (pointCount > 1) { 119 | return true; 120 | } 121 | 122 | switch (ev.getAction()) { 123 | case MotionEvent.ACTION_DOWN: 124 | mIsSetFlying = false; 125 | mIsRvFlyingDown = false; 126 | initOrResetVelocityTracker(); 127 | resetScroller(); 128 | dealWithError(); 129 | break; 130 | case MotionEvent.ACTION_MOVE: 131 | initVelocityTrackerIfNotExists(); 132 | mVelocityTracker.addMovement(ev); 133 | break; 134 | case MotionEvent.ACTION_UP: 135 | case MotionEvent.ACTION_CANCEL: 136 | if (isParentCenter() && mVelocityTracker != null) { 137 | //处理连接处的父控件fling事件 138 | mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); 139 | int yVelocity = (int) -mVelocityTracker.getYVelocity(); 140 | mCurFlyingType = yVelocity > 0 ? FLYING_FROM_WEBVIEW_TO_PARENT : FLYING_FROM_PARENT_TO_WEBVIEW; 141 | recycleVelocityTracker(); 142 | parentFling(yVelocity); 143 | } 144 | break; 145 | } 146 | 147 | return super.dispatchTouchEvent(ev); 148 | } 149 | 150 | @Override 151 | public boolean onTouchEvent(MotionEvent event) { 152 | switch (event.getAction()) { 153 | case MotionEvent.ACTION_DOWN: 154 | mLastY = (int) event.getY(); 155 | break; 156 | case MotionEvent.ACTION_MOVE: 157 | if (mLastY == 0) { 158 | mLastY = (int) event.getY(); 159 | return true; 160 | } 161 | int y = (int) event.getY(); 162 | int dy = y - mLastY; 163 | mLastY = y; 164 | scrollBy(0, -dy); 165 | break; 166 | case MotionEvent.ACTION_CANCEL: 167 | case MotionEvent.ACTION_UP: 168 | mLastY = 0; 169 | break; 170 | } 171 | return true; 172 | } 173 | 174 | @Override 175 | public boolean onInterceptTouchEvent(MotionEvent ev) { 176 | final int action = ev.getAction(); 177 | switch (action & MotionEvent.ACTION_MASK) { 178 | case MotionEvent.ACTION_MOVE: 179 | // 拦截落在不可滑动子View的MOVE事件 180 | final int y = (int) ev.getY(); 181 | final int yDiff = Math.abs(y - mLastMotionY); 182 | boolean isInNestedChildViewArea = isTouchNestedInnerView((int)ev.getRawX(), (int)ev.getRawY()); 183 | if (yDiff > TOUCH_SLOP && !isInNestedChildViewArea) { 184 | mIsBeingDragged = true; 185 | mLastMotionY = y; 186 | final ViewParent parent = getParent(); 187 | if (parent != null) { 188 | parent.requestDisallowInterceptTouchEvent(true); 189 | } 190 | } 191 | break; 192 | case MotionEvent.ACTION_DOWN: 193 | mLastMotionY = (int) ev.getY(); 194 | mIsBeingDragged = false; 195 | break; 196 | case MotionEvent.ACTION_UP: 197 | case MotionEvent.ACTION_CANCEL: 198 | mIsBeingDragged = false; 199 | break; 200 | } 201 | 202 | return mIsBeingDragged; 203 | } 204 | 205 | public void scrollToTarget(View view) { 206 | if (view == null) { 207 | return; 208 | } 209 | if (mChildWebView != null) { 210 | mChildWebView.scrollToBottom(); 211 | } 212 | scrollTo(0, view.getTop() - 100); 213 | } 214 | 215 | private boolean isTouchNestedInnerView(int x, int y) { 216 | List innerView = new ArrayList<>(); 217 | if (mChildWebView != null) { 218 | innerView.add(mChildWebView); 219 | } 220 | if (mChildRecyclerView != null) { 221 | innerView.add(mChildRecyclerView); 222 | } 223 | 224 | for (View nestedView : innerView) { 225 | if (nestedView.getVisibility() != View.VISIBLE) { 226 | continue; 227 | } 228 | int[] location = new int[2]; 229 | nestedView.getLocationOnScreen(location); 230 | int left = location[0]; 231 | int top = location[1]; 232 | int right = left + nestedView.getMeasuredWidth(); 233 | int bottom = top + nestedView.getMeasuredHeight(); 234 | if (y >= top && y <= bottom && x >= left && x <= right) { 235 | return true; 236 | } 237 | } 238 | return false; 239 | } 240 | 241 | @Override 242 | protected void onDetachedFromWindow() { 243 | super.onDetachedFromWindow(); 244 | if (mScroller != null) { 245 | mScroller.abortAnimation(); 246 | mScroller = null; 247 | } 248 | mVelocityTracker = null; 249 | mChildRecyclerView = null; 250 | mChildWebView = null; 251 | mParentHelper = null; 252 | } 253 | 254 | @Override 255 | public void scrollTo(int x, int y) { 256 | if (y < 0) { 257 | y = 0; 258 | } 259 | if (y > getInnerScrollHeight()) { 260 | y = getInnerScrollHeight(); 261 | } 262 | super.scrollTo(x, y); 263 | } 264 | 265 | @Override 266 | public void computeScroll() { 267 | if (mScroller.computeScrollOffset()) { 268 | int currY = mScroller.getCurrY(); 269 | switch (mCurFlyingType) { 270 | case FLYING_FROM_WEBVIEW_TO_PARENT://WebView向父控件滑动 271 | if (mIsRvFlyingDown) { 272 | //RecyclerView的区域的fling由自己完成 273 | break; 274 | } 275 | scrollTo(0, currY); 276 | invalidate(); 277 | checkRvTop(); 278 | if (getScrollY() == getInnerScrollHeight() && !mIsSetFlying) { 279 | //滚动到父控件底部,滚动事件交给RecyclerView 280 | mIsSetFlying = true; 281 | recyclerViewFling((int) mScroller.getCurrVelocity()); 282 | } 283 | break; 284 | case FLYING_FROM_PARENT_TO_WEBVIEW://父控件向WebView滑动 285 | scrollTo(0, currY); 286 | invalidate(); 287 | if (currY <= 0 && !mIsSetFlying) { 288 | //滚动父控件顶部,滚动事件交给WebView 289 | mIsSetFlying = true; 290 | webViewFling((int) -mScroller.getCurrVelocity()); 291 | } 292 | break; 293 | case FLYING_FROM_RVLIST_TO_PARENT://RecyclerView向父控件滑动,fling事件,单纯用于计算速度。RecyclerView的flying事件传递最终会转换成Scroll事件处理. 294 | if (getScrollY() != 0) { 295 | invalidate(); 296 | } else if (!mIsSetFlying) { 297 | mIsSetFlying = true; 298 | //滑动到顶部时,滚动事件交给WebView 299 | webViewFling((int) -mScroller.getCurrVelocity()); 300 | } 301 | break; 302 | } 303 | } 304 | } 305 | 306 | private NestedScrollingParentHelper getNestedScrollingHelper() { 307 | if (mParentHelper == null) { 308 | mParentHelper = new NestedScrollingParentHelper(this); 309 | } 310 | return mParentHelper; 311 | } 312 | 313 | private void webViewFling(int v) { 314 | if (mChildWebView != null) { 315 | mChildWebView.flingScroll(0, v); 316 | } 317 | } 318 | 319 | private void recyclerViewFling(int v) { 320 | if (mChildRecyclerView != null) { 321 | mChildRecyclerView.fling(0, v); 322 | } 323 | } 324 | 325 | private void findRecyclerView(ViewGroup parent) { 326 | if (mChildRecyclerView != null) { 327 | return; 328 | } 329 | 330 | int count = parent.getChildCount(); 331 | for (int i = 0; i < count; i++) { 332 | View child = parent.getChildAt(i); 333 | if (child instanceof RecyclerView && TAG_NESTED_SCROLL_RECYCLERVIEW.equals(child.getTag())) { 334 | mChildRecyclerView = (RecyclerView) child; 335 | break; 336 | } 337 | if (child instanceof ViewGroup) { 338 | findRecyclerView((ViewGroup) child); 339 | } 340 | } 341 | } 342 | 343 | private void findWebView(ViewGroup parent) { 344 | if (mChildWebView != null) { 345 | return; 346 | } 347 | int count = parent.getChildCount(); 348 | for (int i = 0; i < count; i++) { 349 | View child = parent.getChildAt(i); 350 | if (child instanceof NestedScrollingWebView && TAG_NESTED_SCROLL_WEBVIEW.equals(child.getTag())) { 351 | mChildWebView = (NestedScrollingWebView) child; 352 | break; 353 | } 354 | if (child instanceof ViewGroup) { 355 | findWebView((ViewGroup) child); 356 | } 357 | } 358 | } 359 | 360 | private boolean isParentCenter() { 361 | return getScrollY() > 0 && getScrollY() < getInnerScrollHeight(); 362 | } 363 | 364 | private void scrollToWebViewBottom() { 365 | if (mChildWebView != null) { 366 | mChildWebView.scrollToBottom(); 367 | } 368 | } 369 | 370 | private void initOrResetVelocityTracker() { 371 | if (mVelocityTracker == null) { 372 | mVelocityTracker = VelocityTracker.obtain(); 373 | } else { 374 | mVelocityTracker.clear(); 375 | } 376 | } 377 | 378 | private void initVelocityTrackerIfNotExists() { 379 | if (mVelocityTracker == null) { 380 | mVelocityTracker = VelocityTracker.obtain(); 381 | } 382 | } 383 | 384 | private void recycleVelocityTracker() { 385 | if (mVelocityTracker != null) { 386 | mVelocityTracker.recycle(); 387 | mVelocityTracker = null; 388 | } 389 | } 390 | 391 | private void resetScroller() { 392 | if (!mScroller.isFinished()) { 393 | mScroller.abortAnimation(); 394 | } 395 | if (mChildRecyclerView != null) { 396 | mChildRecyclerView.stopScroll(); 397 | } 398 | } 399 | 400 | /** 401 | * 处理未知的错误情况 402 | */ 403 | private void dealWithError() { 404 | //当父控件有偏移,但是WebView却不在底部时,属于异常情况,进行修复, 405 | //有两种修复方案:1.将WebView手动滑动到底部,2.将父控件的scroll位置重置为0 406 | //目前的测试中没有出现这种异常,此代码作为异常防御 407 | if (isParentCenter() && canWebViewScrollDown()) { 408 | if (getScrollY() > getMeasuredHeight() / 4) { 409 | scrollToWebViewBottom(); 410 | } else { 411 | scrollTo(0, 0); 412 | } 413 | } 414 | } 415 | 416 | private void parentFling(float velocityY) { 417 | mScroller.fling(0, getScrollY(), 0, (int) velocityY, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); 418 | invalidate(); 419 | } 420 | 421 | private void checkRvTop() { 422 | if (isParentCenter() && !isRvTop()) { 423 | rvScrollToPosition(0); 424 | } 425 | } 426 | 427 | private void rvScrollToPosition(int position) { 428 | if (mChildRecyclerView == null) { 429 | return; 430 | } 431 | 432 | mChildRecyclerView.scrollToPosition(position); 433 | RecyclerView.LayoutManager manager = mChildRecyclerView.getLayoutManager(); 434 | if (manager instanceof LinearLayoutManager) { 435 | ((LinearLayoutManager) manager).scrollToPositionWithOffset(position, 0); 436 | } 437 | } 438 | 439 | private boolean isRvTop() { 440 | if (mChildRecyclerView == null) { 441 | return false; 442 | } 443 | return !mChildRecyclerView.canScrollVertically(-1); 444 | } 445 | 446 | private boolean canWebViewScrollDown() { 447 | return mChildWebView != null && mChildWebView.canScrollDown(); 448 | } 449 | 450 | private int getInnerScrollHeight() { 451 | return mInnerScrollHeight; 452 | } 453 | 454 | /****** NestedScrollingParent2 BEGIN ******/ 455 | 456 | @Override 457 | public boolean onStartNestedScroll(@NonNull View child, @NonNull View target, int axes, int type) { 458 | return (axes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0; 459 | } 460 | 461 | @Override 462 | public int getNestedScrollAxes() { 463 | return getNestedScrollingHelper().getNestedScrollAxes(); 464 | } 465 | 466 | @Override 467 | public void onNestedScrollAccepted(@NonNull View child, @NonNull View target, int axes, int type) { 468 | getNestedScrollingHelper().onNestedScrollAccepted(child, target, axes, type); 469 | } 470 | 471 | @Override 472 | public void onStopNestedScroll(@NonNull View target, int type) { 473 | getNestedScrollingHelper().onStopNestedScroll(target); 474 | } 475 | 476 | @Override 477 | public boolean onNestedPreFling(View target, float velocityX, float velocityY) { 478 | if (target instanceof NestedScrollingWebView) { 479 | //WebView滑到底部时,继续向下滑动父控件和RV 480 | mCurFlyingType = FLYING_FROM_WEBVIEW_TO_PARENT; 481 | parentFling(velocityY); 482 | } else if (target instanceof RecyclerView && velocityY < 0 && getScrollY() >= getInnerScrollHeight()) { 483 | //RV滑动到顶部时,继续向上滑动父控件和WebView,这里用于计算到达父控件的顶部时RV的速度 484 | mCurFlyingType = FLYING_FROM_RVLIST_TO_PARENT; 485 | parentFling((int) velocityY); 486 | } else if (target instanceof RecyclerView && velocityY > 0) { 487 | mIsRvFlyingDown = true; 488 | } 489 | 490 | return false; 491 | } 492 | 493 | @Override 494 | public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) { 495 | return false; 496 | } 497 | 498 | @Override 499 | public void onNestedScroll(@NonNull View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { 500 | if (dyUnconsumed < 0) { 501 | //RecyclerView向父控件的滑动衔接处 502 | scrollBy(0, dyUnconsumed); 503 | } 504 | } 505 | 506 | @Override 507 | public void onNestedPreScroll(@NonNull View target, int dx, int dy, @Nullable int[] consumed, int type) { 508 | boolean isWebViewBottom = !canWebViewScrollDown(); 509 | boolean isCenter = isParentCenter(); 510 | if (dy > 0 && isWebViewBottom && getScrollY() < getInnerScrollHeight()) { 511 | //为了WebView滑动到底部,继续向下滑动父控件 512 | scrollBy(0, dy); 513 | if (consumed != null) { 514 | consumed[1] = dy; 515 | } 516 | } else if (dy < 0 && isCenter) { 517 | //为了RecyclerView滑动到顶部时,继续向上滑动父控件 518 | scrollBy(0, dy); 519 | if (consumed != null) { 520 | consumed[1] = dy; 521 | } 522 | } 523 | if (isCenter && !isWebViewBottom) { 524 | //异常情况的处理 525 | scrollToWebViewBottom(); 526 | } 527 | } 528 | } 529 | -------------------------------------------------------------------------------- /app/src/main/java/com/wzy/nesteddetail/view/NestedScrollingWebView.java: -------------------------------------------------------------------------------- 1 | package com.wzy.nesteddetail.view; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.view.NestedScrollingChild2; 7 | import android.support.v4.view.NestedScrollingChildHelper; 8 | import android.support.v4.view.ViewCompat; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.VelocityTracker; 12 | import android.view.View; 13 | import android.view.ViewConfiguration; 14 | import android.webkit.WebView; 15 | import android.widget.Scroller; 16 | 17 | import com.wzy.nesteddetail.utils.DimenHelper; 18 | 19 | public class NestedScrollingWebView extends WebView implements NestedScrollingChild2 { 20 | private boolean mIsSelfFling; 21 | private boolean mHasFling; 22 | 23 | private final int TOUCH_SLOP; 24 | private int mMaximumVelocity; 25 | private int mFirstY; 26 | private int mLastY; 27 | private int mMaxScrollY; 28 | private int mWebViewContentHeight; 29 | private int mJsCallWebViewContentHeight; 30 | 31 | private final int[] mScrollConsumed = new int[2]; 32 | 33 | private final float DENSITY; 34 | 35 | private NestedScrollingChildHelper mChildHelper; 36 | private NestedScrollingDetailContainer mParentView; 37 | private Scroller mScroller; 38 | private VelocityTracker mVelocityTracker; 39 | 40 | public NestedScrollingWebView(Context context) { 41 | this(context, null); 42 | } 43 | 44 | public NestedScrollingWebView(Context context, AttributeSet attrs) { 45 | this(context, attrs, 0); 46 | } 47 | 48 | public NestedScrollingWebView(Context context, AttributeSet attrs, int defStyle) { 49 | super(context, attrs, defStyle); 50 | mChildHelper = new NestedScrollingChildHelper(this); 51 | setNestedScrollingEnabled(true); 52 | mScroller = new Scroller(getContext()); 53 | final ViewConfiguration configuration = ViewConfiguration.get(getContext()); 54 | mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); 55 | TOUCH_SLOP = configuration.getScaledTouchSlop(); 56 | DENSITY = context.getResources().getDisplayMetrics().density; 57 | } 58 | 59 | /** 60 | * 设置JS回调的Web内容高度,解决内部计算不准导致的问题 61 | */ 62 | public void setJsCallWebViewContentHeight(int webViewContentHeight) { 63 | if (webViewContentHeight > 0 && webViewContentHeight != mJsCallWebViewContentHeight) { 64 | mJsCallWebViewContentHeight = webViewContentHeight; 65 | if (mJsCallWebViewContentHeight < getHeight()) { 66 | // 内部高度<控件高度时,调整控件高度为内容高度 67 | DimenHelper.updateLayout(this, DimenHelper.NOT_CHANGE, mJsCallWebViewContentHeight); 68 | } 69 | } 70 | } 71 | 72 | public int getWebViewContentHeight() { 73 | if (mWebViewContentHeight == 0) { 74 | mWebViewContentHeight = mJsCallWebViewContentHeight; 75 | } 76 | 77 | if (mWebViewContentHeight == 0) { 78 | mWebViewContentHeight = (int) (getContentHeight() * DENSITY); 79 | } 80 | 81 | return mWebViewContentHeight; 82 | } 83 | 84 | public boolean canScrollDown() { 85 | final int range = getWebViewContentHeight() - getHeight(); 86 | if (range <= 0) { 87 | return false; 88 | } 89 | 90 | final int offset = getScrollY(); 91 | return offset < range - TOUCH_SLOP; 92 | } 93 | 94 | @SuppressLint("ClickableViewAccessibility") 95 | @Override 96 | public boolean onTouchEvent(MotionEvent event) { 97 | switch (event.getAction()) { 98 | case MotionEvent.ACTION_DOWN: 99 | mWebViewContentHeight = 0; 100 | mLastY = (int) event.getRawY(); 101 | mFirstY = mLastY; 102 | if (!mScroller.isFinished()) { 103 | mScroller.abortAnimation(); 104 | } 105 | initOrResetVelocityTracker(); 106 | mIsSelfFling = false; 107 | mHasFling = false; 108 | mMaxScrollY = getWebViewContentHeight() - getHeight(); 109 | startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); 110 | if (getParent() != null) { 111 | getParent().requestDisallowInterceptTouchEvent(true); 112 | } 113 | break; 114 | case MotionEvent.ACTION_MOVE: 115 | initVelocityTrackerIfNotExists(); 116 | mVelocityTracker.addMovement(event); 117 | int y = (int) event.getRawY(); 118 | int dy = y - mLastY; 119 | mLastY = y; 120 | if (getParent() != null) { 121 | getParent().requestDisallowInterceptTouchEvent(true); 122 | } 123 | if (!dispatchNestedPreScroll(0, -dy, mScrollConsumed, null)) { 124 | scrollBy(0, -dy); 125 | } 126 | if (Math.abs(mFirstY - y) > TOUCH_SLOP) { 127 | //屏蔽WebView本身的滑动,滑动事件自己处理 128 | event.setAction(MotionEvent.ACTION_CANCEL); 129 | } 130 | break; 131 | case MotionEvent.ACTION_CANCEL: 132 | case MotionEvent.ACTION_UP: 133 | if (isParentResetScroll() && mVelocityTracker != null) { 134 | mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); 135 | int yVelocity = (int) -mVelocityTracker.getYVelocity(); 136 | recycleVelocityTracker(); 137 | mIsSelfFling = true; 138 | flingScroll(0, yVelocity); 139 | } 140 | break; 141 | } 142 | super.onTouchEvent(event); 143 | return true; 144 | } 145 | 146 | @Override 147 | public void flingScroll(int vx, int vy) { 148 | mScroller.fling(0, getScrollY(), 0, vy, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); 149 | invalidate(); 150 | } 151 | 152 | @Override 153 | protected void onDetachedFromWindow() { 154 | super.onDetachedFromWindow(); 155 | recycleVelocityTracker(); 156 | stopScroll(); 157 | mChildHelper = null; 158 | mScroller = null; 159 | mParentView = null; 160 | } 161 | 162 | @Override 163 | public void computeScroll() { 164 | if (mScroller.computeScrollOffset()) { 165 | final int currY = mScroller.getCurrY(); 166 | if (!mIsSelfFling) { 167 | // parent flying 168 | scrollTo(0, currY); 169 | invalidate(); 170 | return; 171 | } 172 | 173 | if (isWebViewCanScroll()) { 174 | scrollTo(0, currY); 175 | invalidate(); 176 | } 177 | if (!mHasFling 178 | && mScroller.getStartY() < currY 179 | && !canScrollDown() 180 | && startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL) 181 | && !dispatchNestedPreFling(0, mScroller.getCurrVelocity())) { 182 | //滑动到底部时,将fling传递给父控件和RecyclerView 183 | mHasFling = true; 184 | dispatchNestedFling(0, mScroller.getCurrVelocity(), false); 185 | } 186 | } 187 | } 188 | 189 | @Override 190 | public void scrollTo(int x, int y) { 191 | if (y < 0) { 192 | y = 0; 193 | } 194 | if (mMaxScrollY != 0 && y > mMaxScrollY) { 195 | y = mMaxScrollY; 196 | } 197 | if (isParentResetScroll()) { 198 | super.scrollTo(x, y); 199 | } 200 | } 201 | 202 | void scrollToBottom() { 203 | int y = getWebViewContentHeight(); 204 | super.scrollTo(0, y - getHeight()); 205 | } 206 | 207 | private NestedScrollingChildHelper getNestedScrollingHelper() { 208 | if (mChildHelper == null) { 209 | mChildHelper = new NestedScrollingChildHelper(this); 210 | } 211 | return mChildHelper; 212 | } 213 | 214 | private void initOrResetVelocityTracker() { 215 | if (mVelocityTracker == null) { 216 | mVelocityTracker = VelocityTracker.obtain(); 217 | } else { 218 | mVelocityTracker.clear(); 219 | } 220 | } 221 | 222 | private void initVelocityTrackerIfNotExists() { 223 | if (mVelocityTracker == null) { 224 | mVelocityTracker = VelocityTracker.obtain(); 225 | } 226 | } 227 | 228 | private void recycleVelocityTracker() { 229 | if (mVelocityTracker != null) { 230 | mVelocityTracker.recycle(); 231 | mVelocityTracker = null; 232 | } 233 | } 234 | 235 | private void initWebViewParent() { 236 | if (this.mParentView != null) { 237 | return; 238 | } 239 | View parent = (View) getParent(); 240 | while (parent != null) { 241 | if (parent instanceof NestedScrollingDetailContainer) { 242 | this.mParentView = (NestedScrollingDetailContainer) parent; 243 | break; 244 | } else { 245 | parent = (View) parent.getParent(); 246 | } 247 | } 248 | } 249 | 250 | private boolean isParentResetScroll() { 251 | if (mParentView == null) { 252 | initWebViewParent(); 253 | } 254 | if (mParentView != null) { 255 | return mParentView.getScrollY() == 0; 256 | } 257 | return true; 258 | } 259 | 260 | private void stopScroll() { 261 | if (mScroller != null && !mScroller.isFinished()) { 262 | mScroller.abortAnimation(); 263 | } 264 | } 265 | 266 | private boolean isWebViewCanScroll() { 267 | return getWebViewContentHeight() > getHeight(); 268 | } 269 | 270 | /****** NestedScrollingChild BEGIN ******/ 271 | @Override 272 | public void setNestedScrollingEnabled(boolean enabled) { 273 | getNestedScrollingHelper().setNestedScrollingEnabled(enabled); 274 | } 275 | 276 | @Override 277 | public boolean isNestedScrollingEnabled() { 278 | return getNestedScrollingHelper().isNestedScrollingEnabled(); 279 | } 280 | 281 | @Override 282 | public boolean startNestedScroll(int axes) { 283 | return getNestedScrollingHelper().startNestedScroll(axes); 284 | } 285 | 286 | @Override 287 | public void stopNestedScroll() { 288 | getNestedScrollingHelper().stopNestedScroll(); 289 | } 290 | 291 | @Override 292 | public boolean hasNestedScrollingParent() { 293 | return getNestedScrollingHelper().hasNestedScrollingParent(); 294 | } 295 | 296 | @Override 297 | public boolean dispatchNestedPreScroll(int dx, int dy, @Nullable int[] consumed, @Nullable int[] offsetInWindow) { 298 | return getNestedScrollingHelper().dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow); 299 | } 300 | 301 | @Override 302 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow) { 303 | return getNestedScrollingHelper().dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow); 304 | } 305 | 306 | @Override 307 | public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) { 308 | return getNestedScrollingHelper().dispatchNestedFling(velocityX, velocityY, consumed); 309 | } 310 | 311 | @Override 312 | public boolean dispatchNestedPreFling(float velocityX, float velocityY) { 313 | return getNestedScrollingHelper().dispatchNestedPreFling(velocityX, velocityY); 314 | } 315 | 316 | @Override 317 | public boolean startNestedScroll(int axes, int type) { 318 | return getNestedScrollingHelper().startNestedScroll(axes, type); 319 | } 320 | 321 | @Override 322 | public void stopNestedScroll(int type) { 323 | getNestedScrollingHelper().stopNestedScroll(type); 324 | } 325 | 326 | @Override 327 | public boolean hasNestedScrollingParent(int type) { 328 | return getNestedScrollingHelper().hasNestedScrollingParent(type); 329 | } 330 | 331 | @Override 332 | public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow, int type) { 333 | return getNestedScrollingHelper().dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow, type); 334 | } 335 | 336 | @Override 337 | public boolean dispatchNestedPreScroll(int dx, int dy, @Nullable int[] consumed, @Nullable int[] offsetInWindow, int type) { 338 | return getNestedScrollingHelper().dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow, type); 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 14 | 15 | 23 | 24 | 29 | 30 | 37 | 38 | 43 | 44 | 45 | 46 | 47 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_content_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 30 | 31 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_title_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #171D17 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Android-NestedDetail 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.21' 5 | repositories { 6 | google() 7 | jcenter() 8 | mavenCentral() 9 | 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.4.0' 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | mavenCentral() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536m 2 | 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon May 20 14:58:19 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /screenshot/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wangzhengyi/Android-NestedDetail/36d3c57b6e41d50f3b287ec4297c756327999d40/screenshot/screenshot.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------