第三方jar包:Github上的开源地址:https://github.com/Frank-Zhu/PullZoomView
我们将开源项目下载下来,将library的src目录下的代码copy到自己的工程下
记住还有values目录下的ids和attrs文件,同样copy
集成我们自己的项目
//xml<com.hanju.hanju_my.Three.pulltozoomview.PullToZoomScrollViewEx android:id="@+id/scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" /> xml head_zoom_view <?xml version="1.0" encoding="utf-8"?> <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/head_imageView" android:layout_width="match_parent" android:layout_height="180dp" android:layout_gravity="center_horizontal" android:scaleType="centerCrop" > </ImageView>//java
PullToZoomScrollViewEx scrollView = (PullToZoomScrollViewEx) findViewById(R.id.scroll_view);
loadViewForPullToZoomScrollView(scrollView);//注意初始化顺序,不要弄乱,否则抛出运行时空指针
setPullToZoomViewLayoutParams(scrollView);
}
private void loadViewForPullToZoomScrollView(PullToZoomScrollViewEx scrollView) { // View headView = LayoutInflater.from(this).inflate(R.layout.head_view, null); View zoomView = LayoutInflater.from(this).inflate(R.layout.head_zoom_view, null); // View contentView = LayoutInflater.from(this).inflate(R.layout.content_view, null); // scrollView.setHeaderView(headView); scrollView.setZoomView(zoomView); // scrollView.setScrollContentView(contentView); }
// 设置头部的View的宽高。 private void setPullToZoomViewLayoutParams(PullToZoomScrollViewEx scrollView) { DisplayMetrics localDisplayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics); int mScreenHeight = localDisplayMetrics.heightPixels; int mScreenWidth = localDisplayMetrics.widthPixels; LinearLayout.LayoutParams localObject = new LinearLayout.LayoutParams(mScreenWidth, (int) (9.0F * (mScreenWidth / 16.0F))); scrollView.setHeaderLayoutParams(localObject); }