欢迎光临程序猿零食铺:https://shop66096489.taobao.com
感谢:
https://github.com/Frank-Zhu/PullZoomView
先看效果,来自github上的项目PullZoomView:
地址:https://github.com/Frank-Zhu/PullZoomView,
本篇文章主要针对PullZoomView中的Zoom Scroll View为例子说明如何使用该库,其实使用很简单,就是导入android studio运行的时候碰到了一些坎。
2015年七月底clone到自己android studio的时候,遇到来一个奇葩的问题,不过已经解决,解决方案可点击链接 [Android Debug]aapt.exe” finished with non-zero exit value 1
已经放一份稍微修改过的代码到csdn,下载地址:
http://download.csdn.net/detail/zhouhuakang/8955079
1.PullZoomView的PullToZoomScrollActivity中将一个页面分为三个部分,分别是头部、头部下面用来放大的图片、头部下方显示的内容,利用定制过的PullToZoomScrollViewEx.setxxx方法载入三个部分。
PullToZoomScrollActivity的方法
private void loadViewForCode() {
//载入视图
PullToZoomScrollViewEx scrollView =(PullToZoomScrollViewEx) findViewById(R.id.scroll_view);
View headView = LayoutInflater.from(this).inflate(R.layout.profile_head_view, null, false);
View zoomView = LayoutInflater.from(this).inflate(R.layout.profile_zoom_view, null, false);
View contentView = LayoutInflater.from(this).inflate(R.layout.profile_content_view, null, false);
//加入到ScrollView中
scrollView.setHeaderView(headView);
scrollView.setZoomView(zoomView);
scrollView.setScrollContentView(contentView);
}
2.之后在onCreate中设置头部的高度即可
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 * (mScreenHeight / 16.0F)));
scrollView.setHeaderLayoutParams(localObject);