I am trying to animate an ImageView from a child layout (Relativelayout) into a parent layout (Relative layout). the image will not be colored when entering the parent layout.
enter code
private static final int SWIPE_MIN = 20;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD = 20;
GestureDetector detector;
ImageView topImage;
ImageView bottomImage;
ImageView aView;
RelativeLayout rlBottomChild;
RelativeLayout rlTopChild;
FrameLayout flTopChild;
FrameLayout flBottomChild;
RelativeLayout table;
RelativeLayout relativeLayout ;
FrameLayout frameLayout ;
WindowManager wManger;
int screenWidth;
int screenHeight;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
wManger = getWindowManager();
screenWidth = wManger.getDefaultDisplay().getWidth();
screenHeight = wManger.getDefaultDisplay().getHeight();
detector = new GestureDetector(this);
bottomImage = new ImageView(this);
bottomImage.setImageResource(R.drawable.icon);
bottomImage.setOnTouchListener(this);
bottomImage.setDrawingCacheEnabled(true);
topImage = new ImageView(this);
topImage.setImageResource(R.drawable.icon);
topImage.setOnTouchListener(this);
topImage.setDrawingCacheEnabled(true);
initRelativeLayout();
setContentView(relativeLayout);
}
private void initRelativeLayout() {
rlTopChild = new RelativeLayout(this);
rlTopChild.setId(1);
LayoutParams p2 = new LayoutParams(LayoutParams.FILL_PARENT , ((10*screenHeight)/100));
p2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
rlTopChild.setBackgroundColor(Color.BLUE);
rlTopChild.addView(topImage);
rlTopChild.setLayoutParams(p2);
rlBottomChild = new RelativeLayout(this);
rlBottomChild.setId(3);
LayoutParams p = new LayoutParams(LayoutParams.FILL_PARENT , ((10*screenHeight)/100));
p.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rlBottomChild.setBackgroundColor(Color.BLUE);
rlBottomChild.addView(bottomImage);
rlBottomChild.setClipChildren(false);
rlBottomChild.setLayoutParams(p);
table = new RelativeLayout(this);
table.setId(2);
LayoutParams p3 = new LayoutParams(LayoutParams.FILL_PARENT , ((50*screenHeight)/100));
p3.addRule(RelativeLayout.CENTER_IN_PARENT);
p3.addRule(RelativeLayout.BELOW , rlTopChild.getId());
p3.addRule(RelativeLayout.ABOVE , rlBottomChild.getId());
table.setBackgroundColor(Color.WHITE);
table.setLayoutParams(p3);
relativeLayout =new RelativeLayout(this);
relativeLayout.setBackgroundColor(Color.GREEN);
relativeLayout.addView(rlBottomChild);
relativeLayout.addView(rlTopChild);
relativeLayout.addView(table);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return detector.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH){
return false;
}
if (e1.getX() - e2.getX() > SWIPE_MIN && Math.abs(velocityX) > SWIPE_THRESHOLD) {
debug("Left Swipe");
TranslateAnimation animation= new TranslateAnimation(e1.getX(),e2.getX(),e1.getY() ,e2.getY());
animation.setAnimationListener(this);
animation.setDuration(3000);
bottomImage.startAnimation(animation);
} else if (e2.getX() - e1.getX() > SWIPE_MIN && Math.abs(velocityX) > SWIPE_THRESHOLD) {
debug("Right Swipe ");
debug("Swipe down ...");
TranslateAnimation animation= new TranslateAnimation(e1.getX(),e2.getX(),e1.getY() ,e2.getY());
animation.setAnimationListener(this);
animation.setDuration(3000);
topImage.startAnimation(animation);
} else if (e1.getY() - e2.getY() > SWIPE_MIN && Math.abs(velocityX) > SWIPE_THRESHOLD) {
debug("Swipe up ... ");
TranslateAnimation animation= new TranslateAnimation(e1.getX(),e2.getX(),e1.getY() ,e2.getY());
animation.setAnimationListener(this);
animation.setDuration(3000);
bottomImage.startAnimation(animation);
} else if (e2.getY() - e1.getY() > SWIPE_MIN && Math.abs(velocityX) > SWIPE_THRESHOLD) {
debug("Swipe down ...");
TranslateAnimation animation= new TranslateAnimation(e1.getX(),e2.getX(),e1.getY() ,e2.getY());
animation.setAnimationListener(this);
animation.setDuration(3000);
topImage.startAnimation(animation);
}
} catch (Exception e) {
}
return true;
}
private void debug(String string) {
Log.d("TAGGG", string);
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return true;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
}
here
Thank. jega
source
share