我已经完成了一个 Activity ,其中包含全屏图像和 TextView 下方及其描述。我想要的是在单击图像时使 TextView 不可见。我放了一个 toast ,代码就在那里,但不是不可见的。可能是什么错误?谢谢
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = inflater.inflate(R.layout.ampliar_imagen, view, false);
assert imageLayout != null;
imageView = (TouchImageView) imageLayout.findViewById(R.id.imagenFullScreen);
info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.cargandoFoto);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ImagePagerActivity.this, "CLICK", Toast.LENGTH_SHORT).show();
info.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) {
Toast.makeText(ImagePagerActivity.this, "Error al cargar la imagen", Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
view.addView(imageLayout, 0);
return imageLayout;
}
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>
<TextView
android:id="@+id/textoInfoImagen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/grisTransparente"
android:gravity="center_horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="AAAA"
android:textColor="@color/blanco"
android:textSize="13sp" />
</RelativeLayout>
最佳答案
我建议您将 imageLayout 设置为 imageView 的标签,并在 ImageView 的 onClick 中从标签布局获取您的 textview,然后将其可见性设置为消失或不可见。试试这个。
imageView = (TouchImageView) imageLayout.findViewById(R.id.imagenFullScreen);
info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
imageView.setTag(info);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView tv = (TextView)v.getTag();
tv.setVisibility(View.GONE);
}
关于Android:onClick 图像使 Textview 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22501747/