【问题标题】:Disappearable text on Imageview [duplicate]Imageview上消失的文本[重复]
【发布时间】:2016-06-21 06:49:51
【问题描述】:

我希望我的 ImageView 显示一个占位符消息:the image will display here,该消息应在该 ImageView 上显示图像后立即消失。

谁能给我解决方案?

【问题讨论】:

  • 您能提供在您的 ImageView 上加载图像的代码吗?
  • 您可以有一个可准确说明这一点的可绘制对象,然后一旦从 Web 服务加载图像或您要从中获取它的任何内容,只需将此可绘制对象替换为加载的图像。

标签: android android-imageview textview


【解决方案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);

谢谢...

【讨论】:

    【解决方案2】:

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

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

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

    这样做

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

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

    2) 如果您是从互联网加载它

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

    在 cmets 中询问更多问题

    【讨论】:

    • 感谢您的回答。它奏效了
    • 乐于助人:),,,请标记正确答案;P
    【解决方案3】:

    您可以为此使用 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>
    

    然后在代码中,您可以在成功加载图像时隐藏文本视图

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

    【讨论】:

      【解决方案4】:

      当图片被加载时,它只是出现在文本之上并隐藏它。

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

      【讨论】:

      • 谢谢。它帮助了我
      【解决方案5】:

      执行此操作的常规方法是使用另一个视图(在您的情况下为TextView)替换为在您的情况下正在加载的任何内容(ImageView)。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多