salut tout le monde , voilà , je travaille sur une application android et là j'avais besoin d'utiliser le zoom in et le zoom out
mais il y'a un problème quand j'ouvre ma 1ére activité là où il y'a l'image que je veux zoomer
quant j'appuie sur le zoom in, mon image disparaît puis en cliquant une seconde fois elle s'inverse.
voici mon code Java
et mon code 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 public class carte3 extends Activity implements OnClickListener { private ImageView img; private Button btnZoomIn; private Button btnZoomOut; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.carte3); img = (ImageView) findViewById(R.id.C3); // lorsque on click sur le bouton zoom in pour zoomer btnZoomIn = (Button) findViewById(R.id.btnZoomIn); btnZoomIn.setOnClickListener(this); // lorsgue on click sur le bouton zoom out pour dézoomer btnZoomOut = (Button) findViewById(R.id.btnZoomOut); btnZoomOut.setOnClickListener(this); } @SuppressLint("NewApi") @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnZoomIn: // Here I need Zoom in Code float x = img.getScaleX(); float y = img.getScaleY(); img.setScaleX((float) (x+1)); img.setScaleY((float) (y+1)); break; case R.id.btnZoomOut: // Here I need Zoom out Code float x1 = img.getScaleX(); float y1 = img.getScaleY(); img.setScaleX((float) (x1-1)); img.setScaleY((float) (y1-1)); break; } } }
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 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/C3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/carte3"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btnZoomOut" android:layout_width="32dp" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:layout_marginLeft="0dp" android:background="@android:color/transparent" android:drawableLeft="@drawable/btn_icon_zoom_out" /> <Button android:id="@+id/btnZoomIn" android:layout_width="34dp" android:layout_height="wrap_content" android:layout_marginBottom="15dp" android:layout_marginLeft="10dp" android:background="@android:color/transparent" android:drawableLeft="@drawable/btn_icon_zoom_in" /> </LinearLayout> </LinearLayout>
Partager