0

Here's my layout

          <ImageView
              android:id="@+id/my_img1"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/>

          <ImageView
              android:id="@+id/my_img2"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:visibility="gone"/>

Both ImageView were loaded with glide

Glide.with(MyImg1).load(Img1Url).into(MyImg1)
Glide.with(MyImg2).load(Img2Url).into(MyImg2)

When user click a button I just switch their visibility

    if (MyImg1.visibility == View.VISIBLE) {
        MyImg1.visibility = View.INVISIBLE
        MyImg2.visibility = View.VISIBLE
    }
    else {
        MyImg1.visibility = View.VISIBLE
        MyImg2.visibility = View.INVISIBLE
    }

Now the problem is MyImg2 will always be blank no matter how many times the switch button was click. If I change android:visibility="gone" from my_img2 and put it to my_img1 then MyImg2 will show and this means image loading is fine.

Eddi
  • 479
  • 5
  • 22

2 Answers2

1

Instead of View.INVISIBLE try with View.GONE

if (MyImg1.visibility == View.VISIBLE) {
        MyImg1.visibility = View.GONE
        MyImg2.visibility = View.VISIBLE
    }
    else {
        MyImg1.visibility = View.VISIBLE
        MyImg2.visibility = View.GONE
    }
Vir Rajpurohit
  • 1,869
  • 1
  • 10
  • 23
0

If you are using RelativeLayout as the parent for both of them then add android:layoutparentBelow = "@+id/my_img_1" In your second imageview layout file

Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20