JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
JavaScript
package com.cannibal_photographer;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
public class Boat extends ImageView {
//
bool state = true;
public Boat(Context context, AttributeSet attrs, ImageView boatimage) {
super(context, attrs);
ImageView boatimage = (ImageView)context.findViewById(R.id.imageView1);
boatImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick (View v) {
if (state) {
moveBoatForward(-290);
} else {
moveBoatReverse(290);
}
}
})
}
public void moveBoatForward(int amount){
boatimage.offsetTopAndBottom(amount);
state = !state;
}
public void moveBoatReverse(int amount) {
boatimage.offsetTopAndBottom(290);
state = !state;
}
}