We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如题,嵌套在ViewPage里面,用Glide加载图片,代码中动态创建PhotoView。
启用图片缩放功能photoView.enable(); 后,图片要将近3秒才能显示出来(本地图片);
// 禁用图片缩放功能photoView.disenable();后,图像不到1秒就显示出来了;
请问有遇到这个情况吗?
附:代码片段:
package com.simope.eccs.ui.other;
import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.TextView;
import com.bumptech.glide.Glide; import com.simope.eccs.R; import com.simope.eccs.base.BaseActivity; import com.simope.eccs.widget.PhotoView;
import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.Extra; import org.androidannotations.annotations.ViewById;
import java.util.ArrayList; import java.util.List;
/**
Created by User9527 on 2017/5/10.
图片浏览器页面 */ @EActivity(R.layout.activity_image_viewer) public class ImageViewerActivity extends BaseActivity {
@ViewById ViewPager mViewPager;
@ViewById TextView mTextView;
@AfterViews public void initData() { // 全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager .LayoutParams.FLAG_FULLSCREEN); // 初始化PhotoView图片浏览器的列表 mImageList = new ArrayList<>(); // 单条图片地址 if (!TextUtils.isEmpty(imageUrl) && positionImage == 0) { mImageList.add(getPhotoView(imageUrl)); } // 图片地址列表 if (null != imageUrlList && !imageUrlList.isEmpty()) { mImageList.clear(); for (String url : imageUrlList) { mImageList.add(getPhotoView(url)); } } // 设置ViewPager if (null != mImageList && !mImageList.isEmpty() && positionImage < mImageList.size()) { // 设置适配器 mViewPager.setAdapter(new ImagePagerAdapter()); // 监听滑动事件 mViewPager.addOnPageChangeListener(mOnPageChangeListener); // 设置当前显示坐标 mViewPager.setCurrentItem(positionImage); // 设置指示器 setIndicator(); } }
监听ViewPager滑动事件 */ private OnPageChangeListener mOnPageChangeListener = new OnPageChangeListener() {
@OverRide public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@OverRide public void onPageSelected(int position) { // 设置指示器 setIndicator(); }
@OverRide public void onPageScrollStateChanged(int state) {
} };
ViewPager适配器 */ class ImagePagerAdapter extends PagerAdapter {
@OverRide public int getCount() { return mImageList.size(); }
@OverRide public boolean isViewFromObject(View view, Object object) { return view == object; }
@OverRide public Object instantiateItem(ViewGroup container, int position) { container.addView(mImageList.get(position)); return mImageList.get(position); }
@OverRide public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(mImageList.get(position)); } }
----------------------------------xml --------------------------------
<android.support.v4.view.ViewPager android:id="@+id/mViewPager" android:layout_width="match_parent" android:layout_height="match_parent" /> <TextView android:id="@+id/mTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|center_horizontal" android:text="@string/app_name" android:textColor="@android:color/white"/>
The text was updated successfully, but these errors were encountered:
猜测是不是请求太多 有没有懒加载
Sorry, something went wrong.
No branches or pull requests
如题,嵌套在ViewPage里面,用Glide加载图片,代码中动态创建PhotoView。
启用图片缩放功能photoView.enable(); 后,图片要将近3秒才能显示出来(本地图片);
// 禁用图片缩放功能photoView.disenable();后,图像不到1秒就显示出来了;
请问有遇到这个情况吗?
附:代码片段:
package com.simope.eccs.ui.other;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.simope.eccs.R;
import com.simope.eccs.base.BaseActivity;
import com.simope.eccs.widget.PhotoView;
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.Extra;
import org.androidannotations.annotations.ViewById;
import java.util.ArrayList;
import java.util.List;
/**
Created by User9527 on 2017/5/10.
图片浏览器页面
*/
@EActivity(R.layout.activity_image_viewer)
public class ImageViewerActivity extends BaseActivity {
@ViewById
ViewPager mViewPager;
@ViewById
TextView mTextView;
/**
/
@extra
String imageUrl;
/*
/
@extra
ArrayList imageUrlList;
/*
/
@extra
int positionImage;
/*
*/
private List mImageList;
@AfterViews
public void initData() {
// 全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager
.LayoutParams.FLAG_FULLSCREEN);
// 初始化PhotoView图片浏览器的列表
mImageList = new ArrayList<>();
// 单条图片地址
if (!TextUtils.isEmpty(imageUrl) && positionImage == 0) {
mImageList.add(getPhotoView(imageUrl));
}
// 图片地址列表
if (null != imageUrlList && !imageUrlList.isEmpty()) {
mImageList.clear();
for (String url : imageUrlList) {
mImageList.add(getPhotoView(url));
}
}
// 设置ViewPager
if (null != mImageList && !mImageList.isEmpty() && positionImage < mImageList.size()) {
// 设置适配器
mViewPager.setAdapter(new ImagePagerAdapter());
// 监听滑动事件
mViewPager.addOnPageChangeListener(mOnPageChangeListener);
// 设置当前显示坐标
mViewPager.setCurrentItem(positionImage);
// 设置指示器
setIndicator();
}
}
/**
*/
private PhotoView getPhotoView(String imageUrl) {
// 创建一个PhotoView图片浏览器
PhotoView pv = new PhotoView(this);
// 设置开启缩放模式 更多操作参考:https://github.com/bm-x/PhotoView
pv.enable();
// 用Glide加载图片
Glide.with(this).load(imageUrl).fitCenter().into(pv);
// 设置点击关闭页面
pv.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View view) {
finish();
}
});
return pv;
}
/**
监听ViewPager滑动事件
*/
private OnPageChangeListener mOnPageChangeListener = new OnPageChangeListener() {
@OverRide
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@OverRide
public void onPageSelected(int position) {
// 设置指示器
setIndicator();
}
@OverRide
public void onPageScrollStateChanged(int state) {
}
};
/**
*/
private void setIndicator() {
mTextView.setText((mViewPager.getCurrentItem() + 1) + " / " + mImageList.size());
}
/**
ViewPager适配器
*/
class ImagePagerAdapter extends PagerAdapter {
@OverRide
public int getCount() {
return mImageList.size();
}
@OverRide
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@OverRide
public Object instantiateItem(ViewGroup container, int position) {
container.addView(mImageList.get(position));
return mImageList.get(position);
}
@OverRide
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(mImageList.get(position));
}
}
}
----------------------------------xml --------------------------------
The text was updated successfully, but these errors were encountered: