【发布时间】:2011-10-12 10:09:15
【问题描述】:
现在我想在每个触摸事件中更改 img1 的上边距(每个触摸事件向下 10 px)。下面是我的代码。我已将此代码放在我活动的触摸事件中。
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++;
现在边距仅在一次触摸事件中更改,而不是在每个触摸事件中更改。
所以我希望用户的每一次触摸图像都应该下降 10 像素
【问题讨论】:
标签: android layout margin touch-event