Layout TextView and EditText differences, layout_width and lay_weight differences--android Studio

Source: Internet
Author: User

1. TextView control is a text representation control, the main function is to show the user the content of the text, it is not editable, such as setting the title; The EditText control is the edit text control, the main function is to let the user enter the text content, it can be edited.
Each control has its own properties, and it can achieve different effects by selecting different properties and giving them values.
2. When the Layout_width property value is set to Wrap_content, only enough space is available to depict itself, as well as additional space. The Layout_weight property value for additional space allocation.
If layout_width= "0DP", only the Layout_weight property value is considered.
<linearlayout
android:orientation= "Horizontal"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:layout_marginleft= "16DP"
android:layout_marginright= "16DP" >

<button
android:text= "button"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:id= "@+id/crime_date"
android:layout_weight= "1"
/>
<checkbox
Android:id= "@+id/crime_solved"
android:text= "@string/crime_solved_label"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "16DP"
android:layout_marginright= "16DP"
android:layout_weight= "1"/>
</LinearLayout>
such as code: LinearLayout has two controls, a Button and a checkbox.

The first step is to view the Layout_width property value (view Layout_height in the vertical direction). Because when set to Wrap_content, the space available is only enough to depict itself, and there is extra space.
The second step LinearLayout additional space allocations based on the attribute values of the layout_weight. Two sub-component property values are the same as 1. Because the same size of the extra space is evenly divided. If the layout_weight of the button is set to a value of 2, 2/3 of the extra space will be obtained.
The checkbox component obtains the remaining 1/3.







Layout TextView and EditText differences, layout_width and lay_weight differences--android Studio

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.