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

标签 android swap zooming

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

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/

相关文章:

google-maps - 谷歌地图 - 缩放和居中不起作用

wxpython - 绘图程序通用缩放算法

Android 11 权限问题

android - Polar Wearlink 蓝牙数据包

c++ - 专门化函数模板的语法

java - 缩放后屏幕坐标和图像坐标之间的转换

java - Android - 无法解析 org.jetbrains.kotlin :kotlin-gradle-plugin:1. 6.10

java - Android 将 Int 转换为 Hex 颜色

c++ - 为什么 std::future<T> 和 std::shared_future<T> 不提供成员 swap()?

javascript - 用 Javascript 交换 <p>