
linearLayout layMain = (linearLayout) findVIEwByID(R.ID.layout_main); layMain.setontouchListener((OntouchListener) this);
// ————–
public boolean ontouch(VIEw arg0,MotionEvent arg1) { // Get the action that was done on this touch event switch (arg1.getAction()) { case MotionEvent.ACTION_DOWN: { // store the X value when the user's finger was pressed down downXValue = arg1.getX(); break; } case MotionEvent.ACTION_UP: { // Get the X value when the user released his/her finger float currentX = arg1.getX(); // going backwards: pushing stuff to the right if (downXValue < currentX) { // Get a reference to the VIEwFlipper VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details); // Set the animation vf.setoutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_right_in)); // Flip! vf.showPrevIoUs(); } // going forwards: pushing stuff to the left if (downXValue > currentX) { // Get a reference to the VIEwFlipper VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details); // Set the animation // vf.setInAnimation(AnimationUtils.loadAnimation(this,// R.anim.push_left_in)); vf.setoutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out)); vf.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in)); // Flip! vf.showNext(); } break; } } // if you return false,these actions will not be recorded return true; } 每个屏幕都包含一个ImageVIEw.so,当我切换屏幕时,imagevIEw正在改变.现在我想实现这个:当点击一个图像时,一个url是打开的.这是我的代码:
VIEwFlipper vf = (VIEwFlipper) findVIEwByID(R.ID.details); for (i = 0; i < jArray.length(); i++) { linearLayout l = new linearLayout(this); l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); l.setBackgroundcolor(0x000000); l.setorIEntation(linearLayout.VERTICAL); vf.addVIEw(l); ImageVIEw img = new ImageVIEw(this); img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); Drawable image1 = ImageOperations(getBaseContext(),url[i]); img.setimageDrawable(image1); System.out.println("target" + target[i]); img.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { // Todo auto-generated method stub Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri .parse("http://Google.com")); startActivity(browserIntent); } }); l.addVIEw(img); } 问题是,每当我触摸屏幕时,网址都会打开,现在我无法在屏幕之间切换.如何做到这一点,使onClick()和touch()之间的差异?
请帮我..
提前致谢
if (downXValue == currentX) {Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri .parse("http://Google.com")); startActivity(browserIntent);} 总结 以上是内存溢出为你收集整理的android – 在setOnClickListener和setOnTouchListener之间创建不同的东西全部内容,希望文章能够帮你解决android – 在setOnClickListener和setOnTouchListener之间创建不同的东西所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)