Android: not displayed ImageView with UIL and TouchImageView(Android:不显示带有 UIL 和 TouchImageView 的 ImageView)
问题描述
我正在尝试使用 Universal Image Loader
和 zoom
实现从 URL
加载图像 TouchImageView Mike Ortiz代码>.但是在尝试查看图像时,会显示黑屏.我已检查 URL 是否正确.如果我在那里看到一个 TextView...
I'm trying to implement load images from a URL
with Universal Image Loader
and zoom
with TouchImageView Mike Ortiz
. But when trying to view the image, black screen is displayed. I have checked that the URLs are correct. I if I see a TextView there...
我做错了什么?
ImagePagerActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_fullscreen_view);
Bundle bundle = getIntent().getExtras();
assert bundle != null;
String[] imageUrls = bundle.getStringArray("urls");
int pagerPosition = bundle.getInt("pos", 0);
tipo = bundle.getString("tipo");
monumento = bundle.getString("monumento");
num = bundle.getInt("num");
for(int i = 0; i < imageUrls.length; i++) {
// URLS with data
Toast.makeText(this, "URL = " + imageUrls[i], 0).show();
}
if (savedInstanceState != null) {
pagerPosition = savedInstanceState.getInt(STATE_POSITION);
}
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.imagen)
.showImageOnFail(R.drawable.imagen)
.resetViewBeforeLoading(true)
.cacheOnDisc(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
pager = (ExtendedViewPager) findViewById(R.id.pager);
pager.setAdapter(new ImagePagerAdapter(imageUrls));
pager.setCurrentItem(pagerPosition);
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(STATE_POSITION, pager.getCurrentItem());
}
private class ImagePagerAdapter extends PagerAdapter {
private String[] images;
private LayoutInflater inflater;
ImagePagerAdapter(String[] images) {
this.images = images;
inflater = getLayoutInflater();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object instantiateItem(ViewGroup view, int position) {
final View imageLayout = inflater.inflate(R.layout.ampliar_imagen, view, false);
assert imageLayout != null;
imageView = (TouchImageView) imageLayout.findViewById(R.id.imagenFullScreen);
infoImagen = (LinearLayout)imageLayout.findViewById(R.id.textoInfoImagen);
info = (TextView) imageLayout.findViewById(R.id.textoInfoImagenDesc);
cargarInfo(position, images);
android.graphics.PorterDuff.Mode.MULTIPLY);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout infoImagen = (LinearLayout)imageLayout.findViewById(R.id.textoInfoImagen);
if(infoImagen.getVisibility() == View.GONE) {
infoImagen.setVisibility(View.VISIBLE);
} else {
infoImagen.setVisibility(View.GONE);
}
}
});
imageLoader.displayImage(images[position], imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
view.addView(imageLayout, 0);
return imageLayout;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
}
@Override
public Parcelable saveState() {
return null;
}
}
private void cargarInfo(int position, String[] images) {
if(tipo.equals("fotos")) {
info.setText((position + 1) + " de " + images.length +
"
" + InfoImagenes.devolverInfoFotos(monumento, position, num, ImagePagerActivity.this));
}
else if(tipo.equals("planos")) {
info.setText((position + 1) + " de " + images.length +
"
" + InfoImagenes.devolverInfoPlanos(position, num, ImagePagerActivity.this));
}
}
activity_full_screen.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<imagenes.ExtendedViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
ampliar_imagen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/negro" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<imagenes.TouchImageView
android:id="@+id/imagenFullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true" />
<ProgressBar
android:id="@+id/cargandoFoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>
<LinearLayout
android:id="@+id/textoInfoImagen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/grisTransparente"
android:orientation="horizontal"
android:visibility="visible" >
<TextView
android:id="@+id/textoInfoImagenDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:textColor="@color/blanco"
android:textSize="13sp" />
</LinearLayout>
</RelativeLayout>
编辑
如果我通过 ImageView 更改 TouchImageView 它会显示图像
If I change TouchImageView by ImageView it display the image
推荐答案
我也遇到了这个问题,发现和ProgressBar
的可见性有关,可以用下面的代码解决它.
I also met this problem, I found it is related with ProgressBar
's visibility, and the following code can be used to solve it.
- 在
onLoadingStarted()
中,添加view.setVisibility(View.GONE)
- 在
onLoadingComplete()
中,添加view.setVisibility(View.VISIBLE)
- In
onLoadingStarted()
, addview.setVisibility(View.GONE)
- In
onLoadingComplete()
, addview.setVisibility(View.VISIBLE)
代码:
imageLoader.displayImage(imageUri.toString(),
mPictureView,
options,
new SimpleImageLoadingListener()
{
@Override
public void onLoadingStarted(String imageUri, View view)
{
spinner.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason)
{
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
{
spinner.setVisibility(View.GONE);
view.setVisibility(View.VISIBLE);
}
});
这篇关于Android:不显示带有 UIL 和 TouchImageView 的 ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android:不显示带有 UIL 和 TouchImageView 的 ImageView
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01