gpt4 book ai didi

android - 如何在android中设置手指触摸功能?

转载 作者:搜寻专家 更新时间:2023-11-01 07:39:03 25 4
gpt4 key购买 nike

我正在 android 中开发一个小应用程序,其中我的应用程序中几乎没有图像我想要当用户用一根手指触摸时图像可以向左或向右移动,当用户可以用两根手指触摸时它可以缩放我怎么能这样做请为我引用一些教程代码。这是我的代码我在 xml v fdjf 中使用了 view flipper

public class Jaap extends Activity implements OnTouchListener{

float downXValue;
int counter = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

// Set main.XML as the layout for this Activity
setContentView(R.layout.jaap);

// Add these two lines
LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main);
layMain.setOnTouchListener((OnTouchListener) this);

// Add a few countries to the spinner

}

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.setAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
// Flip!
if(counter > 0){
vf.showPrevious();
counter--;
}
}
// 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));
// Flip!
if(counter < 131){
vf.showNext();
counter++;
}
}
break;
}
}

// if you return false, these actions will not be recorded
return true;
}
}

最佳答案

查看 this分步教程,它包含如何放大/缩小图片并四处移动的代码示例。

关于android - 如何在android中设置手指触摸功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6385730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com