利用java线程显示所有图片,给给个图片添加线程;
public void update(final String photoid, final ImageView imageView) //下载照片 { new Thread(new Runnable() { @Override public void run() { Bitmap b = null; OSSCredentialProvider credentialProvider = new OSSPlainTextAKSKCredentialProvider(ACCESS_ID, ACCESS_KEY); ClientConfiguration conf = new ClientConfiguration(); conf.setConnectionTimeout(15 * 1000); // 连接超时,默认15秒 conf.setSocketTimeout(15 * 1000); // socket超时,默认15秒 conf.setMaxConcurrentRequest(8); // 最大并发请求数,默认5个 conf.setMaxErrorRetry(2); // 失败后最大重试次数,默认2次 // oss为全局变量,OSS_ENDPOINT是一个OSS区域地址 oss = new OSSClient(getContext(), OSS_ENDPOINT, credentialProvider, conf); //构造下载文件请求 //objectKey等同于objectName,表示从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg GetObjectRequest get = new GetObjectRequest("sean1246", photoid); //设置下载进度回调 get.setProgressListener(new OSSProgressCallback<GetObjectRequest>() { @Override public void onProgress(GetObjectRequest request, long currentSize, long totalSize) { OSSLog.logDebug("getobj_progress:" + currentSize + "total_size:" + totalSize, false); } }); try { // 同步执行下载请求,返回结果 GetObjectResult getResult = oss.getObject(get); Log.d("Content-Length是", "" + getResult.getContentLength()); // 获取文件输入流 InputStream inputStream = getResult.getObjectContent(); b = BitmapFactory.decodeStream(inputStream); final Bitmap finalB1 =b; final Bitmap finalB2 = zoomImg(cropBitmap(b),230); getActivity().runOnUiThread(new Runnable() { //必须在主线程显示照片 public void run() { final phototheard p=new phototheard(); imageView.setImageBitmap(finalB2); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { progressBar.setVisibility(View.VISIBLE); Log.d("长度", String.valueOf(finalB2.getByteCount()/1024/1024)+"兆"+ ",M宽度为" + finalB2.getWidth() + "高度为" + finalB2.getHeight()); LayoutInflater factory = LayoutInflater.from(getActivity()); vi = factory.inflate(R.layout.showinfo, null); LinearLayout l=vi.findViewById(R.id.linear1); ImageView imageView1=new ImageView(getContext()); imageView1.setImageBitmap(zoomImg(finalB1,1000)); l.addView(imageView1); advancedGeneral(finalB2,photoid); } }); } }); ObjectMetadata metadata = getResult.getMetadata(); Log.d("ContentType", metadata.getContentType()); } catch (ClientException e) { // 本地异常如网络异常等 e.printStackTrace(); } catch (ServiceException e) { // 服务异常 Log.e("RequestId", e.getRequestId()); Log.e("ErrorCode", e.getErrorCode()); Log.e("HostId", e.getHostId()); Log.e("RawMessage", e.getRawMessage()); } } }).start(); }