图片下拉缩小放大效果

第三方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

oncreate{

    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);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值