android - Linking code layout with xml layout file -


i created activity 9 grey blocks on background using following code:

    paint paint = new paint();     paint.setcolor(color.black);     paint.setstrokewidth(5);      canvas.drawline(width/3, 0, width/3, height, paint);     canvas.drawline((2*width)/3, 0, (2*width)/3, height, paint);     canvas.drawline(0, height/3, width, height/3, paint);     canvas.drawline(0, (2*height/3), width  , (2*height)/3, paint);      log.d("game","in draw");      imageview imageview = new imageview(this);     imageview.setimagebitmap(bitmap);       layout = new relativelayout(this);      relativelayout.layoutparams params = new     relativelayout.layoutparams(layoutparams.wrap_content,         layoutparams.wrap_content);     layout.setid(1);     params.addrule(relativelayout.center_in_parent);     layout.addview(imageview, params);     layout.setbackgroundcolor(color.black);     log.d("game","before content view");      // show layout in our activity.     setcontentview(layout); 

so have created layout purely code. want link layout xml file such change in file or in code seen in activity. how so.

you can if class extend activity,listactivity,...etc.

public class mainactivity extends activity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);       } } 

you can change or add layout code:

setcontentview(r.layout.activity_main); //activity_main layout can change 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -