仿淘宝 查看物流
?https://s31.aconvert.com/convert/p3r68-cdx67/q6j5q-077yc.gif
CoordinatorLayout配合AppBarLayout、CollapsingToolbarLayout、Toolbar使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/group_title" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="433dp"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<CollapsingWebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="433dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.99" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
解决AppBarLayout嵌套WebView滑动冲突的问题
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class CollapsingWebView extends WebView {
private GestureDetector detector;
private boolean isScrollBottom = false;
public CollapsingWebView(Context context) {
this(context, null);
}
public CollapsingWebView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CollapsingWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
detector = new GestureDetector(context, new SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
if (!isScrollBottom) {
requestDisallowInterceptTouchEvent(true);
} else {
isScrollBottom = false;
}
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
float webcontent = getContentHeight() * getScale();
float webnow = getHeight() + getScrollY();
isScrollBottom = (Math.abs(webcontent - webnow) < 1);
return true;
}
});
init();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
detector.onTouchEvent(event);
return super.onTouchEvent(event);
}
private void init() {
setWebViewClient(new WebViewClient());
setWebChromeClient(new WebChromeClient());
getSettings().setLoadWithOverviewMode(true);
getSettings().setJavaScriptEnabled(true);
getSettings().setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
getSettings().setBlockNetworkImage(false);
}
}
|