Imageview上的可消除文本

时间:2016-06-21 06:49:52

标签: android android-imageview textview

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

有人能为我提供解决方案吗?

5 个答案:

答案 0 :(得分:1)

    <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);

感谢...

答案 1 :(得分:0)

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

  

1)如果您只是在本地查看(没有互联网)

只需制作与图像视图大小相同的图像,并使用绘画或任何其他编辑器编写&#34;图像将显示在此处&#34;

OR

这样做

<RelativeLayout>
<TextView 

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

加载图片时此textView的setVisibility为VIEW.INVISIBLE

  

2)如果您从互联网上加载

有一个名为piccasso的lib(google it)你可以使用它具有所有功能

在评论中提出更多问题

答案 2 :(得分:0)

您可以使用FrameLayout或RelativeLayout。 e.g

    <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

e.g。 mImageLoaderTextView.setVisibility(imageLoaded ? View.GONE : View.VISIBLE);

答案 3 :(得分:0)

加载图像时,它只会显示在文本上方并隐藏它。

<?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>

答案 4 :(得分:0)

执行此操作的传统方法是将另一个视图(在您的情况下为TextView)替换为您的案例中的任何加载(ImageView)。

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