This article is an example of the dynamic modification of Android programming relativelayout wide-height method. Share to everyone for your reference, specific as follows:
We often dynamically modify the relativelayout, such code, relatively simple, is to modify the Relativelayout Layoutparams can. The code is generally as follows:
Relativelayout ss = (relativelayout) Findviewbyid (r.id.myrelativelayout);
Ss.setlayoutparams (New Relativelayout.layoutparams (width, height));
This kind of modification, in most cases, no problem, and very useful, but I encountered the problem is that I want to modify the Relativelayout, the whole layout of the middle part.
Here I want to change is the middle green life this box, if we use the above method, you will find that the height of the relativelayout has indeed been changed, but he changed the overall layout, the top line of the toolbar to the whole. As follows
This is not what we want. How does this change? In fact, you look at the code, you can understand, the above method, he new a layoutparams, the problem is here, the correct way is to first get---> Modify---> and then Set
The code is as follows:
Relativelayout.layoutparams linearparams = (relativelayout.layoutparams) rela_addnote_notetype.getlayoutparams ();
Linearparams.height =;
Rela_addnote_notetype.setlayoutparams (Linearparams);
Try again this time, as shown
I hope this article will help you with the Android program.