webview - Adding dynamic web views in android -
i going through various links on topic. haven't found useful in case. want create web view
in android dynamically. add nothing onto xml layout file. want 2 things in particular: 1. want set size of web view custom width , height , set @ bottom of layout. 2. once page loads in web view. on click on web view should resize , go full screen(which means fill_parent on width , height web view in parent layout).
my current code looks below not work particularly full screen not fit content screen:
public class mainactivity extends activity { relativelayout layout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); layout=(relativelayout)findviewbyid(r.id.test); final webview web = new webview(this); //web.setid(1); web.getsettings().setjavascriptenabled(true); web.loaddata("<script type=\"text/javascript\" src=\"http://www..myurl.com/myfolder/banner.php\"></script>", null, null); layout.addview(web, new layoutparams(300,100)); web.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { // todo auto-generated method stub web.setlayoutparams(new layoutparams(layoutparams.match_parent,layoutparams.match_parent)); return false; } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
if understand problem correctly, may want consider following approach.
first, declare , initialize (parent) relative layout, parameters , set content view (delete setcontentview(r.layout.activity_main);).
final relativelayout layout = new relativelayout(this); final relativelayout.layoutparams params = new relativelayout.layoutparams( getwindowmanager().getdefaultdisplay().getwidth(), getwindowmanager().getdefaultdisplay().getheight()); layout.setlayoutparams(params); setcontentview(layout);
then, initialize web view , parameters, , add "bottom rule" parameters.
final webview web = new webview(this); web.getsettings().setjavascriptenabled(true); web.loaddata( "<script type=\"text/javascript\" src=\"http://www..myurl.com/myfolder/banner.php\"></script>", null, null); relativelayout.layoutparams webviewparams = new relativelayout.layoutparams( 300, 100); webviewparams.addrule(relativelayout.align_parent_bottom);
finally, add web view (parent) relative layout , add listener.
layout.addview(web, webviewparams); web.setontouchlistener(new ontouchlistener() { public boolean ontouch(view arg0, motionevent arg1) { web.setlayoutparams(params); return false; } });
hope needed.
cheers!
Comments
Post a Comment