简体   繁体   中英

android studio Make a textView below an imageview visible if imageview has no image

I have an imageView that should display the icon of an profile from an url. But it can happen that the url has no image and for this case i want to have an textview underneath it. If the imageView is "empty" the user should b able to see the text n the textView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.user.lolstats.DisplayDataActivity">

<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/imgRound"
    android:layout_width="125dp"
    android:layout_height="125dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:background="#00000000"
    android:foregroundGravity="center"
    android:visibility="visible"
    app:border_color="#ffffff"
    app:border_width="10dp" />

<TextView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_above="@+id/TVsummoerName"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="11dp"
    android:gravity="center"
    android:text="If you can read this your SummonerIcon isn't implemented yet." />

<TextView
    android:id="@+id/TVsummoerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/imgRound"
    android:gravity="center" />
</RelativeLayout>

您可以设置可见性

imageview.setVisibility(View.GONE); // visible / invisible acc to your need

put ImageView in another relative layout

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.user.lolstats.DisplayDataActivity">


        <RelativeLayout 
          android:layout_width="wrap_content"
          android:id="@+id/rl"
          android:layout_height="wrap_content">

        <de.hdodenhof.circleimageview.CircleImageView
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:id="@+id/imgRound"
         android:layout_width="125dp"
         android:layout_height="125dp"
         android:layout_centerHorizontal="true"
         android:layout_marginTop="10dp"
         android:background="#00000000"
         android:foregroundGravity="center"
         android:visibility="visible"
         app:border_color="#ffffff"
         app:border_width="10dp" />

    </RelativeLayout>


    <TextView
    android:id="@+id/TVsummoerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@id/rl"
    android:gravity="center" />
    </RelativeLayout>

The TextView will be below the relative layout Now programmatically set imageView invisible

ImageView.setVisibility(View.INVISIBLE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM