Reputation: 1893
I have a shape defined as a drawable:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#0075b5"/>
<size android:height="2dp"/>
</shape>
and I use this shape in an ImageView as source:
<ImageView android:layout_height="2dp"
android:layout_width="fill_parent"
android:src="@drawable/shape_blue_line"
android:id="@+id/ptt_blueLineImageView"/>
The problem appears when I want to toggle my ImageView:
private void toggleAnimatedLogo() {
if (viewFlipper.getDisplayedChild() == 2) {
animatedLogo.setAlpha(ALHPA_TRANSPARENT);
blueLine.setAlpha(ALHPA_TRANSPARENT);
} else {
animatedLogo.setAlpha(ALHPA_VISIBLE);
blueLine.setAlpha(ALHPA_VISIBLE);
}
}
The result is that on first execution of this method both ImageViews disappears but only the animated one appears on the second. The line since disappearing don't want to show at all. I would like to have a working toggle method.
Upvotes: 0
Views: 934
Reputation: 1893
So it was really weird behaviour of ImageView. After I made some layout changes in the layout file, which were for sure unrelated (I've checked) to this issue the code started to work. Anyone knows why this happened?
Anyway, I've discovered this after pasting this code above my blueLine in layout xml. The previous line started to work then. After cutting it up again it still works.
<View android:layout_height="2dp"
android:layout_width="fill_parent"
android:id="@+id/ptt_blueLineView"
android:background="#0075b5"/>
Eventually, I decided to stay with this new version of line, abandoning shapes...
Upvotes: 0
Reputation: 9189
This might be better accomplished with View.setVisibility(), use View.INVISIBLE if you still want the ImageView layed-out or View.Gone if you want it to ignore layout.
Upvotes: 1