How to display Text for all sizes in same position in android -
i need display alphabet 'a' starting postion should top line postion , end postion should bottom line of screen.. of screen ..i displayed top , bottom lines using view..in sizes of screens top , bottom lines displaying fine...but problem in alphabet displaying 1 screen remain screens not displaying properly...i tried using below code..please 1 suggest me
public class extends activity { mediaplayer nextsound,mediay2; myview myview; relativelayout relativelayout, relativelayout1,relativelayoutmain; float screenheight, screenwidth, screendensity; float lefta, topa; public boolean action = false; button start,stop,next,back,home,erase,horn; boolean count = true; relativelayout.layoutparams lp61; sampleview sampleview; int username; string user; bundle b; bitmap bmp1; static bitmap bmp3; int lst; view content; string fname,name; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); displaymetrics displaymetrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(displaymetrics); screenheight = displaymetrics.heightpixels; screenwidth = displaymetrics.widthpixels; screendensity = displaymetrics.densitydpi; setcontentview(r.layout.alh); relativelayoutmain = (relativelayout) findviewbyid(r.id.relativemain); relativelayout = (relativelayout) findviewbyid(r.id.relative); relativelayout.layoutparams layoutrel = (relativelayout.layoutparams) relativelayout .getlayoutparams(); layoutrel.topmargin = (int) (5 * (screenheight / 600)); layoutrel.bottommargin = (int) (5 * (screenheight / 600)); layoutrel.leftmargin = (int) (5 * (screenwidth / 1024)); layoutrel.rightmargin= (int) (5 * (screenwidth / 1024)); relativelayout1 = (relativelayout) findviewbyid(r.id.relative2); relativelayout.layoutparams layoutre2 = (relativelayout.layoutparams) relativelayout1 .getlayoutparams(); layoutre2.topmargin = (int) (5 * (screenheight / 600)); layoutre2.bottommargin = (int) (5 * (screenheight / 600)); layoutre2.leftmargin = (int) (5 * (screenwidth / 1024)); layoutre2.rightmargin= (int) (5 * (screenwidth / 1024)); sampleview = new sampleview(this); lp61 = new relativelayout.layoutparams( android.view.viewgroup.layoutparams.wrap_content, android.view.viewgroup.layoutparams.wrap_content); sampleview.setlayoutparams(lp61); lp61.setmargins(0, 0, 0, 0); int scaledsize = getresources().getdimensionpixelsize(r.dimen.myfontsize); textview t1=(textview)findviewbyid(r.id.alphabets); relativelayout.layoutparams layoutt1 = (relativelayout.layoutparams)t1 .getlayoutparams(); layoutt1.leftmargin = (int) (100 * (screenwidth /1024)); typeface font = typeface.createfromasset(getassets(), "font/kindtrg.ttf"); t1.settypeface(font); t1.settextsize(scaledsize); t1.settext("a"); back=(button)findviewbyid(r.id.back); relativelayout.layoutparams layoutback = (relativelayout.layoutparams)back .getlayoutparams(); layoutback.height = (int) (55 * (screenheight / 600)); layoutback.width = (int) (55 * (screenwidth /1024)); back.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub } }); next=(button)findviewbyid(r.id.next); relativelayout.layoutparams layoutnext = (relativelayout.layoutparams)next .getlayoutparams(); layoutnext.height = (int) (55 * (screenheight / 600)); layoutnext.width = (int) (55 * (screenwidth /1024)); next.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub } }); erase=(button)findviewbyid(r.id.erase); relativelayout.layoutparams layouterase = (relativelayout.layoutparams)erase .getlayoutparams(); layouterase.height = (int) (100 * (screenheight / 600)); layouterase.width = (int) (100 * (screenwidth /1024)); layouterase.topmargin = (int) (40 * (screenheight /600)); layouterase.leftmargin = (int) (300 * (screenwidth /1024)); erase.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub try { mbitmap.erasecolor(android.graphics.color.transparent); canvas canvas = new canvas(mbitmap); action = true; myview.ondraw(canvas); } catch (illegalstateexception ie) { ie.printstacktrace(); } } }); horn=(button)findviewbyid(r.id.horn); relativelayout.layoutparams layouthorn = (relativelayout.layoutparams)horn .getlayoutparams(); layouthorn.height = (int) (75 * (screenheight / 600)); layouthorn.width = (int) (75 * (screenwidth /1024)); layouthorn.topmargin = (int) (40 * (screenheight /600)); layouthorn.leftmargin = (int) (700 * (screenwidth /1024)); horn.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub } }); home=(button)findviewbyid(r.id.home); relativelayout.layoutparams layouthome = (relativelayout.layoutparams)home .getlayoutparams(); layouthome.height = (int) (60 * (screenheight / 600)); layouthome.width = (int) (60 * (screenwidth /1024)); layouthome.leftmargin = (int) (490 * (screenwidth /1024)); home.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub bmp1= content.getdrawingcache(); overlay(bmp1); getscreen(); } }); start=(button)findviewbyid(r.id.btn1); relativelayout.layoutparams layoutstart = (relativelayout.layoutparams)start .getlayoutparams(); layoutstart.height = (int) (50 * (screenheight / 600)); layoutstart.width = (int) (50 * (screenwidth /1024)); layoutstart.topmargin = (int) (15 * (screenheight / 600)); layoutstart.leftmargin = (int) (460 * (screenwidth /1024)); start.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub if (count == true) { relativelayoutmain.addview(sampleview, lp61); count = false; } } }); stop=(button)findviewbyid(r.id.btn2); relativelayout.layoutparams layoutstop = (relativelayout.layoutparams)stop .getlayoutparams(); layoutstop.height = (int) (50 * (screenheight / 600)); layoutstop.width = (int) (50 * (screenwidth /1024)); layoutstop.topmargin = (int) (15 * (screenheight / 600)); layoutstop.leftmargin = (int) (520 * (screenwidth /1024)); stop.setonclicklistener(new onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub toast.maketext(a.this,"cccglobal.date.......",toast.length_long).show(); if (count == false) { relativelayoutmain.removeview(sampleview); count = true; } } }); myview = new myview(this); myview.setid(004); final relativelayout.layoutparams lp6 = new relativelayout.layoutparams( android.view.viewgroup.layoutparams.wrap_content, android.view.viewgroup.layoutparams.wrap_content); myview.setlayoutparams(lp6); lp6.setmargins(0, 0, 0, 0); relativelayout1.addview(myview, lp6); mpaint = new paint(); mpaint.setantialias(true); mpaint.setdither(true); mpaint.setcolor(color.black); mpaint.setstyle(paint.style.stroke); mpaint.setstrokejoin(paint.join.round); mpaint.setstrokecap(paint.cap.round); mpaint.setstrokewidth(6); } private paint mpaint; public void colorchanged(int color) { mpaint.setcolor(color); } private bitmap mbitmap; public class myview extends view { private canvas mcanvas; private path mpath; private paint mbitmappaint; public myview(context context) { super(context); // todo auto-generated constructor stub mpath = new path(); mbitmappaint = new paint(paint.dither_flag); } @override protected void onsizechanged(int w, int h, int oldw, int oldh) { super.onsizechanged(w, h, oldw, oldh); if (mbitmap != null) { mbitmap.recycle(); mbitmap = null; } mbitmap = bitmap.createbitmap(w, h, bitmap.config.argb_8888); mcanvas = new canvas(mbitmap); } @override protected void ondraw(canvas canvas) { paint painto = new paint(); painto.setantialias(true); painto.setstrokewidth(3); painto.setstyle(paint.style.fill); paint p1 = new paint(); int scaledsize = getresources().getdimensionpixelsize(r.dimen.myfontsize); p1.settextsize(scaledsize); p1.setantialias(true); typeface font = typeface.createfromasset(getassets(), "font/kindtrg.ttf"); p1.settypeface(font); int topy111 = (int) (86 * (screenheight / 600)); int topy11 = (int) (375 * (screenheight / 600)); int topy21 = (int) (217 * (screenheight / 600)); int leftx21 = (int) (600 * (screenwidth / 1024)); int leftx11 = (int) (960 * (screenwidth / 1024)); canvas.drawline(leftx11, topy111, leftx21, topy111, painto); canvas.drawline(leftx11, topy11, leftx21, topy11, painto); lefta = (int) (70 * (screenwidth / 1024)); topa = (int) (350 * (screenheight / 600)); canvas.drawbitmap(mbitmap, 0, 0, mbitmappaint); canvas.drawpath(mpath, mpaint); dashpatheffect dashpath = new dashpatheffect(new float[]{30,15}, 1); paint painto1= new paint(); painto1.setantialias(true); painto.setstyle(paint.style.fill); painto1.setpatheffect(dashpath); painto1.setstrokewidth(3); canvas.drawline(leftx11, topy21 , leftx21, topy21, painto1); if (action) { invalidate(); } } private float mx, my; private float touch_tolerance = 2; private void touch_start(float x, float y) { mpath.reset(); mpath.moveto(x, y); mx = x; = y; } private void touch_move(float x, float y) { float dx = math.abs(x - mx); float dy = math.abs(y - my); if (dx >= touch_tolerance || dy >= touch_tolerance) { mpath.quadto(mx, my, (x + mx) / 2, (y + my) / 2); mx = x; = y; } } private void touch_up() { mpath.lineto(mx, my); // commit path our offscreen mcanvas.drawpath(mpath, mpaint); // kill don't double draw mpath.reset(); } @override public boolean ontouchevent(motionevent event) { float x = event.getx(); float y = event.gety(); switch (event.getaction()) { case motionevent.action_down: touch_start(x, y); invalidate(); break; case motionevent.action_move: touch_move(x, y); invalidate(); break; case motionevent.action_up: touch_up(); invalidate(); break; } return true; } } class sampleview extends view { inputstream = null; private movie mmovie; private long mmoviestart; private byte[] streamtobytes(inputstream is) { bytearrayoutputstream os = new bytearrayoutputstream(1024); byte[] buffer = new byte[1024]; int len; try { while ((len = is.read(buffer)) >= 0) { os.write(buffer, 0, len); } } catch (java.io.ioexception e) { } return os.tobytearray(); } public sampleview(context context) { super(context); setfocusable(true); // if (is == null) { = context.getresources().openrawresource(r.drawable.a); } if (true) { mmovie = movie.decodestream(is); } else { byte[] array = streamtobytes(is); mmovie = movie.decodebytearray(array, 0, array.length); } } protected void ondraw(canvas canvas) { long = android.os.systemclock.uptimemillis(); if (mmoviestart == 0) { mmoviestart = now; } if (mmovie != null) { int dur = mmovie.duration(); if (dur == 0) { dur = 1000; } int reltime = (int) ((now - mmoviestart) % dur); mmovie.settime(reltime); int lef1 = (int) (0 * (screenwidth / 1024)); int top1 = (int) (0 * (screenheight / 600)); mmovie.draw(canvas, lef1, top1); invalidate(); } } } }
Comments
Post a Comment