我正在我的应用程序中使用ImageAdapter,我希望隐藏文本视图下面的图像。但是setInvisibility不起作用。 El问题与信息无关。观点有问题吗......我需要帮助
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<imagenes.TouchImageView
android:id="@+id/imgDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/textoInfoImagen"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@color/grisTransparente"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:text=""
android:textSize="13sp"
android:textColor="@color/gris"/>
</RelativeLayout>
JAVA
public class FullScreenImageAdapter extends PagerAdapter implements OnClickListener {
private Activity _activity;
private LayoutInflater inflater;
Context context;
String[] listaImagenes;
String monumento;
TouchImageView imgDisplay;
TextView info;
boolean invisible = false;
public FullScreenImageAdapter(Activity activity, Context context, String monumento) throws IOException {
this._activity = activity;
this.context = context;
this.monumento = monumento;
listaImagenes = context.getAssets().list(this.monumento);
}
@Override
public int getCount() {
return listaImagenes.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
inflater = (LayoutInflater) _activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View viewLayout = inflater.inflate(R.layout.ampliar_imagen, container,
false);
imgDisplay = (TouchImageView) viewLayout.findViewById(R.id.imgDisplay);
imgDisplay.setMaxZoom(4);
Bitmap bitmap = cargarImagen(monumento, position);
imgDisplay.setImageBitmap(bitmap);
info = (TextView) viewLayout.findViewById(R.id.textoInfoImagen);
info.setText((position + 1) + " de " + listaImagenes.length +
"\n" + InfoImagenes.devolverInfoImagenes(monumento, position));
imgDisplay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "click", Toast.LENGTH_SHORT).show();
if(invisible == true) {
invisible = false;
info.setVisibility(View.VISIBLE);
} else {
invisible = true;
info.setVisibility(View.INVISIBLE);
}
}
});
((ViewPager) container).addView(viewLayout);
return viewLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((RelativeLayout) object);
}
public Bitmap cargarImagen(String monumento, int position) {
Bitmap bitmap = null;
InputStream is;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
is = context.getAssets().open(monumento + "/" + listaImagenes[position]);
bitmap = BitmapFactory.decodeStream(is, null, options);
} catch (IOException e) {
}
return bitmap;
}
@Override
public void onClick(View v) {
}
}
答案 0 :(得分:0)
info
是您的适配器的成员变量,并且不一定是被点击的相同视图 - 您覆盖每个项目的变量。
onClick()
附带View v
参数,即被点击的视图 - 在其上调用setVisibility()
。
此外,invisible
是一个成员变量,具有与上述相同的问题。如果您想检查视图的当前可见性,请致电v.getVisibility()
。
答案 1 :(得分:0)
将 .java 类中的ImageView
&#39; s(imgDisplay)类型用作ImageView
而不是TouchImageView