mira89 Posted June 30, 2011 Share Posted June 30, 2011 Bonjour! Pour pouvoir placer mes widgets en fct de la taille de l'ecran j'ai écrit ce code pour déterminer respectivement la largeur et longueur de mon ecran : public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); layout=(LinearLayout)findViewById(R.id.layout); int heigh=layout.getHeight(); int width=layout.getWidth(); Toast.makeText(this,String.valueOf(heigh)+""+String.valueOf(width),Toast.LENGTH_LONG).show(); } malheureusemt ce code ne semble fonctionner car j'ai comme resultat 0 0 Est ce qq pourrait m'aider ? Link to comment Share on other sites More sharing options...
nbbu Posted June 30, 2011 Share Posted June 30, 2011 Bonjour! Pour pouvoir placer mes widgets en fct de la taille de l'ecran j'ai écrit ce code pour déterminer respectivement la largeur et longueur de mon ecran : public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); layout=(LinearLayout)findViewById(R.id.layout); int heigh=layout.getHeight(); int width=layout.getWidth(); Toast.makeText(this,String.valueOf(heigh)+""+String.valueOf(width),Toast.LENGTH_LONG).show(); } malheureusemt ce code ne semble fonctionner car j'ai comme resultat 0 0 Est ce qq pourrait m'aider ? Ton layout est il étendu sur toute la surface de ton écran ? (ie android:layout_width="fill_parent" android:layout_height="fill_parent"). Car si il est vide avec l'attribut wrap_content, c'est logique que ça renvoie 0. Enfin c'est juste une idée. Link to comment Share on other sites More sharing options...
mira89 Posted June 30, 2011 Author Share Posted June 30, 2011 mon layout s'étend sur tte la surface(fiil_parent sur height et width) voila la solution ke g trouvé apès qq recherche:p Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); et ca fonctionne!!:P Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.