Imageview 上的消失文本

Disappearable text on Imageview

我希望我的 ImageView 显示占位符消息:the image will display here,一旦图像显示在该 ImageView 上,它就会消失。

谁能给我解决方案?

不确定您使用的是什么,所以我将涵盖所有选项

1) If you are just viewing it locally(without internet)

只需制作一个与图像视图大小相同的图像,然后使用画图或任何其他编辑器编写 "the image will display here"

这样做

<RelativeLayout>
<TextView 

android:text = "the image will display here"
android:id = "@+id/text"/>
<ImageView ..... android:id = "@+id/image"/>
</RelativeLayout>

加载图像时将此 textView 的可见性设置为 VIEW.INVISIBLE

2) If you are loading it from internet

有一个名为 piccasso 的库(google 它)您可以使用它具有所有功能

在评论中提出更多问题

您可以为此使用 FrameLayout 或 RelativeLayout。例如

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/myImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content""
            android:src="@drawable/my_image"
            android:contentDescription="@string/MY_IMAGE" />

        <TextView
            android:id="@+id/imageLoaderText"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_alignBottom="@+id/myImage"
            android:layout_centerHorizontal="true"
            android:text="@string/IMAGE_LOADING" />

    </RelativeLayout>

然后在代码中你可以在成功加载图片时隐藏textview

例如mImageLoaderTextView.setVisibility(imageLoaded ? View.GONE : View.VISIBLE);

加载图像时,它只是出现在文本上并将其隐藏。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_gravity="center"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher" />
</FrameLayout>
    <RelativeLayout
     ... >


       <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
         android:visibility="gone"
       ...
       />

       <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="the image will display here"
       ...
       />

    </RelativeLayout>

将此用作占位符.. 反之亦然

iv.setVisibility(View.VISIBLE);
   tv.setVisibility(View.GONE);

谢谢...

传统的方法是用另一个视图(TextView 在您的情况下)替换为您的情况下正在加载的任何内容(ImageView)。

我通常使用 ViewSwitcher 来做到这一点。