Salutations à tous !
Je reviens du Chat ou personne n'a pu m'aider !
Un problème très simple que voici :
J'ai une vue, qui contient un layout collé au bords de l'écran.
Dans le layout, j'ai une imageview collée au bord du layout.
Lorsque je souhaite afficher la largeur de cette imageview, ça ne fonctionne pas (revois 0 [zero]). Pourtant, quand je lui demande la même chose mais dans un évenement onTouch de cette image, ça fonctionne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageView1g" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2.13" android:src="@drawable/home" /> </LinearLayout>
Pourquoi ?
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 package com.test; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.*; public class MainActivity extends Activity { private ImageView imageViewCarte; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.imageViewCarte = (ImageView) findViewById(R.id.imageView1g); Toast.makeText(this,"Fonctionne pas : "+ imageViewCarte.getWidth(), Toast.LENGTH_SHORT).show(); this.imageViewCarte.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent e) { MainActivity.this.imageViewCarte = (ImageView) findViewById(R.id.imageView1g); Toast.makeText(MainActivity.this,"Fonctionne : "+ imageViewCarte.getWidth(), Toast.LENGTH_SHORT).show(); return false; } }); } }
Partager