how I can get the height of a screen in android? -


i'am trying develop app item goes down , when touch screen rises, have 2 smarthphones , 1 larger other , want greater speed @ item dropped in small. class (no extends activity)

public class vistajuego extends view{ grafico item; public vistajuego(context context, attributeset attrs) {     super(context, attrs);  item = new grafico(this, drawablefaba); } @override protected void onsizechanged(int w, int h, int oldw, int oldh) {     super.onsizechanged(w, h, oldw, oldh);      item.setposx(w/2);     item.setposy(h/2);     item.setheightcanvas(h);     item.setwidthcanvas(w);     height=h;     width=w;       if(h<=800){         item.setincreasey(7);//increase speed posy x 7     }else{         item.setincreasey(15);//increase speed posy x 7     } } 

and can't use displaymetrics because class not extends activity. idea?? pleaseee

you can still use displaymetrics. simple way pass in context. since view, don't need that- it's done you. use getcontext() activity, can call function on activity need- such getcontext().getresources().getdisplaymetrics();


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -