Bonjour,
J'aimerai effectuer un zoom sur mon application mobile, pour l'instant je n'ai fait que dessiner des lignes horizontales et verticales afin d'avoir un plan, sur mon canvas, quelqu'un pourrait il m'aider ? Je me suis renseigner sur le sujet et j'ai trouvé plein de tuto qui sont facilement compréhensible mais ils sont différent de ce que je veux car dans leur cas le zoom s'effectue sur une image alors que moi j'aimerai pouvoir zoomer mon plan.
Voici mon code :
IndoorActivity :
StartActivity :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class IndoorActivity extends Activity implements OnClickListener { public Plan plan; private int typeMenuActivated = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.indoor); plan = (Plan) findViewById(R.id.plan); plan.setActivity(this); } @Override public void onClick(View arg0) { // TODO Auto-generated method stub } public int getTypeMenuActivated() { return typeMenuActivated; } public void setTypeMenuActivated(int typeMenuActivated) { this.typeMenuActivated = typeMenuActivated; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class StartActivity extends Activity implements OnClickListener { private ImageButton indoor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_activity); indoor = (ImageButton) findViewById(R.id.indoor); indoor.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == indoor) { Intent in = new Intent(this, IndoorActivity.class); startActivity(in); } } }
Plan :
indoor.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Plan extends View { private Paint paint = new Paint(); private IndoorActivity activity; public static double scale = 10.0; private Bitmap quadrillage_echelle; public static final int NULL = 0; public Plan(Context context) { super(context); } public Plan(Context context, AttributeSet attrs) { super(context, attrs); } /** * Dessine le repère dans la vue * * @version 1.0 */ private Bitmap drawEchelle() { if (scale != 0) { quadrillage_echelle = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(quadrillage_echelle); Paint paint = new Paint(); canvas.drawText("1 m", (float) ((getWidth() / scale - 3.5) * scale), (float) (2 * scale), paint); canvas.drawLine((float) ((getWidth() / scale - 4) * scale), (float) (2.5 * scale), (float) ((getWidth() / scale - 4) * scale), (float) (3.5 * scale), paint); canvas.drawLine((float) ((getWidth() / scale - 4) * scale), (float) (3 * scale), (float) ((getWidth() / scale - 2) * scale), (float) (3 * scale), paint); canvas.drawLine((float) ((getWidth() / scale - 2) * scale), (float) (2.5 * scale), (float) ((getWidth() / scale - 2) * scale), (float) (3.5 * scale), paint); paint.setColor(Color.argb(20, 0, 0, 0)); paint.setStrokeWidth(1); for (float x = 0; x < getWidth(); x = x + (float) scale) { canvas.drawLine(x, 0, x, getHeight(), paint); } for (float y = 0; y < getHeight(); y = y + (float) scale) { canvas.drawLine(0, y, getWidth(), y, paint); } paint.setStrokeWidth(3); return quadrillage_echelle; } return null; } public IndoorActivity getAttachedActivity() { return activity; } public static double getScale() { return 2 * scale; } @Override protected void onDraw(Canvas canvas) { canvas.save(); paint.setStyle(Style.FILL_AND_STROKE); Bitmap tmp = drawEchelle(); if (tmp != null) canvas.drawBitmap(tmp, 0, 0, paint); } @Override public boolean performClick() { return super.performClick(); } public void setActivity(IndoorActivity activity) { this.activity = activity; } public void setScale(double scale) { Plan.scale = scale; } }
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/MenuGlobal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@color/lightGray" android:orientation="vertical" > </RelativeLayout> <com.example.ligne.indoor.Plan android:id="@+id/plan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/MenuGlobal" /> </RelativeLayout>
start_activity :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".StartActivity" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_margin="0px" android:padding="0px" > <ImageButton android:id="@+id/indoor" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0px" android:padding="0px" android:src="@drawable/play" /> </RelativeLayout> </RelativeLayout>
Partager