Android about SetWidth () and setheight () not responding to the problem

Source: Internet
Author: User

In the Android development process, the height of the control, width, although in XML with android:layout_height= "Match_parent" Set the height (match_parent and fill_parent are the same, After the 2.2 version, Match_parent was replaced with Fill_parent. But sometimes, the program needs to be in the code, dynamically set the height or width of the control.

I take it for granted setheight (100), set the height, thought this would be possible, but did not take effect, Google for a long time have no results, desperate. Later in an article found the answer.

When the height of the set is less than the original default height, call SetHeight (), is not effective, this time to set:

?
123 edittext= (EditText) Findviewbyid (r.id.myedittext); //Edittext.setheight (10); Does not take effect edittext.getlayoutparams (). Height = 100 ;//This setting takes effect.

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.