Android:onClick图像使隐形Textview

时间:2014-03-19 09:43:43

标签: android view onclick onclicklistener invisible

我已经完成了一个活动,其中包含全屏图像和文本视图下方的描述。我想要的是当我点击图像时制作隐形文本视图。我已经放了一个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>

6 个答案:

答案 0 :(得分:1)

我建议你将imageLayout设置为imageView的标签,并在onClick of image view中从标签布局中获取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);

     } 

答案 1 :(得分:0)

而不是这个

info.setVisibility(View.GONE);

使用它: -

info.setVisibility(View.INVISIBLE);

在xml中将可见性设置为textview: -

   <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=""
        **android:visibility="visible"**
        android:textColor="@color/blanco"
        android:textSize="13sp" />

答案 2 :(得分:0)

在你的xml集中,

      android:visibility="true"
      //in textview

并在您的活动中

              info.setVisibility(View.INVISIBLE);

答案 3 :(得分:0)

组     info.setalpha(0.0F);     //对于隐形

组         info.setalpha(1.0F);           //可见

答案 4 :(得分:0)

您可以在onclick事件中定义textview,如下所示

  imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

 TextView info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
 info.setVisibility(View.GONE);//or you can invisible,

 }

        });

答案 5 :(得分:0)

Toast.makeText(getBaseContext(), "CLICK", Toast.LENGTH_SHORT).show();