【发布时间】:2016-11-01 22:11:46
【问题描述】:
所以这里是简单转换的代码,从top_left到bottom_right,我不明白为什么我必须返回false才能让onTouch()正常工作,
1.如果我设置 return true, one a single touch ,它会将 counter 从 0 设置为 3 ,或者只是将 2 或 3 添加到 counter 并且大部分时间都保持在当前位置。
2.如果我设置return false,程序运行正常,按照写的,即counter++;
public class MainActivity extends AppCompatActivity {
Button b;
TextView tv;
public static int counter_button=0,counter=0;
RelativeLayout.LayoutParams old_rules;
RelativeLayout rl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b= (Button) findViewById(R.id.b1);
tv= (TextView) findViewById(R.id.tv1);
rl= (RelativeLayout) findViewById(R.id.rl);
old_rules= (RelativeLayout.LayoutParams) b.getLayoutParams();
rl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
my_changes_touch();
return false;
}
});
}
public void my_changes_touch(){
RelativeLayout.LayoutParams rules= new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
if(counter%2==0) {
counter++;
tv.setText(" "+counter);
rules.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rules.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
b.setLayoutParams(rules);
rules.height=400;
rules.width=400;
b.setLayoutParams(rules);
getContentTransitionManager().beginDelayedTransition(rl);
} else {
counter++;
tv.setText(" "+counter);
b.setLayoutParams(old_rules);
getContentTransitionManager().beginDelayedTransition(rl);
}
}
}
【问题讨论】:
标签: android android-animation android-transitions android-touch-event