Lag al mover imageview (touch)
Publicado por 70n1 (5 intervenciones) el 02/02/2016 00:42:50
Buenas gente, espero que todo bien por hay.
La cosa es que estoy desarollando un control para el PC. (Streaming de la pantalla y manejo del raton desde android)
El touch va perfectamente, pero cuando junto la clase touch con la clase de streaming el touch se relentiza con mucho lag.
Sabeis el porque?
Este es el codigo del touch class
La cosa es que estoy desarollando un control para el PC. (Streaming de la pantalla y manejo del raton desde android)
El touch va perfectamente, pero cuando junto la clase touch con la clase de streaming el touch se relentiza con mucho lag.
Sabeis el porque?
Este es el codigo del touch class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
public class Touchpad {
private ViewGroup mainLayout;
private ImageView image;
private ImageView image1;
private TextView text1;
private TextView text2;
private Display display;
private int xDelta;
private int yDelta;
Context mContext;
void EmpesarTouchpad(Activity a, Context b)
{
mainLayout = (RelativeLayout) a.findViewById(R.id.root);
image = (ImageView) a.findViewById(R.id.img);
image1 = (ImageView) a.findViewById(R.id.img1);
text1=(TextView) a.findViewById(R.id.textView1);
text2=(TextView) a.findViewById(R.id.textView2);
this.mContext = b;
display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
image1.setOnTouchListener(onTouchListener());
//Quitamos la barra de título de nuestra aplicación
}
private OnTouchListener onTouchListener() {
return new OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent event) {
final int x = (int) event.getRawX();
final int y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams)
image.getLayoutParams();
xDelta = x - lParams.leftMargin;
yDelta = y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) image
.getLayoutParams();
if((x - xDelta)<0){break;};
if((y - yDelta)<0){break;};
if((x - xDelta)>display.getWidth()){break;};
if((y - yDelta)>display.getHeight()){break;};
layoutParams.leftMargin = x - xDelta;
layoutParams.topMargin = y - yDelta;
layoutParams.rightMargin = 0;
layoutParams.bottomMargin = 0;
image.setLayoutParams(layoutParams);
text1.setText(Integer.toString(x - xDelta));
text2.setText(Integer.toString(y - yDelta));
break;
}
image.invalidate();
return true;
}
};
}
}
Valora esta pregunta


0