Open wmailn opened 6 years ago
如题,嵌套在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;
/**
图片浏览器页面 */ @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 --------------------------------
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:orientation="vertical">
<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"/>
猜测是不是请求太多 有没有懒加载
如题,嵌套在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;
/**
图片浏览器页面 */ @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 --------------------------------
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:orientation="vertical">