The method of dynamically modifying Relativelayout width in Android programming _android

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.