Now I want to change the top margin(10 px down in every touch event) of img1 in every touch event.Below is my code.I have put this code in the touch event of my activity.
public static int count=0;
int place=-300;
System.out.println("Count is:"+count);
if(count>0)
{
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(0, place, 0, 0);
ImageView imageView=(ImageView)findViewById(R.id.img1);
// MarginLayoutParams marginLayoutParams=new MarginLayoutParams(imageView.getLayoutParams());
//marginLayoutParams.setMargins(0, 500, 0, 0);
imageView.setLayoutParams(lp);
place=place+10;
}
count++;
Now the margin is changed only in one touch event not in every touch event.
So I want that every touch of user the image should come down by 10 px
if for every touch event above code executes… local “place” variable will be initialized to -300 each time , hence place = place + 10 will always result -290 px , please declare place variable in class level , like your count variable. Hope, this will work for you.