AndroidStudio onClick not triggered

Wednesday, November 4, 2015

I'm trying to cross-fade from one ImageView to another ImageView, using the onClick method. This is not a problem, but when I attempt to create an additional onClick method on the second image to cross-fade back, the initial imageView onClick does not trigger. Any ideas why this is?



Here is my xml code I'm using a relative layout and am just matching the ImageView to match both the width and height of the parent aka take up the whole screen.



Complete xml



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main" tools:context=".MainActivity">


Image1



<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/boobies"
android:src="@drawable/niceboobs"
android:onClick="fadeOut" />


Image2



    <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/nina"
android:src="@drawable/ninasexy"
android:alpha="0"
android:onClick="fadeIn"/>

</RelativeLayout>


And these are my two onClick methods, I repeat when I just have the first method or second method they individually work but when I put them both only the second one works.



onClick method 1



  public void fadeOut(View view){

ImageView boobs = (ImageView) findViewById(R.id.boobies);
ImageView nina = (ImageView) findViewById(R.id.nina);

boobs.animate().alpha(0f).setDuration(2000);
nina.animate().alpha(1f).setDuration(2000);

}


onClick method 2



    public void fadeIn(View view){


ImageView boobs = (ImageView) findViewById(R.id.boobies);
ImageView nina = (ImageView) findViewById(R.id.nina);

boobs.animate().alpha(1f).setDuration(2000);
nina.animate().alpha(0f).setDuration(2000);

}

0 comments:

Post a Comment