<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000"> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" /> <TextView android:id="@+id/tv_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:textColor="#ffffff" android:textSize="30sp" /> </RelativeLayout>
/**
* Created by zheng on 2017/11/27.
*/
public class PhotoFragment extends Fragment {
private String url;
private PhotoView mPhotoView;
/**
* 获取这个fragment需要展示图片的url
* @param url
* @return
*/
public static PhotoFragment newInstance(String url) {
PhotoFragment fragment = new PhotoFragment();
Bundle args = new Bundle();
args.putString("url", url);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
url = getArguments().getString("url");
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_img, container, false);
mPhotoView = view.findViewById(R.id.photoview);
//设置缩放类型,默认ScaleType.CENTER(可以不设置)
mPhotoView.setScaleType(ImageView.ScaleType.CENTER);
mPhotoView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
ToastUtils.showToast(getContext(),"长按事件");
return true;
}
});
mPhotoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
@Override
public void onPhotoTap(View view, float x, float y) {
ToastUtils.showToast(getContext(),"点击事件,真实项目中可关闭activity");
}
});
Glide.with(getContext())
.load(url)
.placeholder(R.mipmap.ic_launcher)//加载过程中图片未显示时显示的本地图片
.error(R.mipmap.ic_launcher)//加载异常时显示的图片
// .centerCrop()//图片图填充ImageView设置的大小
.fitCenter()//缩放图像测量出来等于或小于ImageView的边界范围,该图像将会完全显示
.into(mPhotoView);
return view;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <uk.co.senab.photoview.PhotoView android:id="@+id/photoview" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.chrisbanes.photoview:library:+'
compile 'com.github.bumptech.glide:glide:3.7.0'
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有