Getting Started with Android (i)

Source: Internet
Author: User

Linear layout
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "44DP"android:orientation= "Horizontal">    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "44DP"android:layout_gravity= "Center"Android:background= "#ff0000"android:ellipsize= "End"Android:layout_weight= "1"android:gravity= "Center"Android:singleline= "true"Android:text= "111111111111111111111111" />    <TextViewAndroid:layout_width= "Match_parent"android:layout_gravity= "Center"Android:layout_weight= "1"Android:background= "#000000"Android:text= "2222222222222" />    <TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "44DP"android:layout_gravity= "Center"Android:background= "#ff0000"Android:layout_weight= "1"android:ellipsize= "End"android:gravity= "Center"Android:singleline= "true"Android:text= "111111111111" /></LinearLayout>

Set the Layout_weight=1 attribute to divide the parent space for each textview. Can be done beyond the hidden text.

Or

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "44DP"android:orientation= "Horizontal">    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"android:layout_gravity= "Center"Android:background= "#ff0000"android:gravity= "Center"Android:text= "111111111111111111111111" />    <TextViewAndroid:layout_width= "Match_parent"android:layout_gravity= "Center"Android:layout_weight= "1"Android:background= "#000000"Android:text= "2222222222222" />    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "44DP"android:layout_gravity= "Center"Android:background= "#ff0000"android:gravity= "Center"Android:text= "111111111111" /></LinearLayout>

Only to the middle of the TextView set android:layout_weight=1, open space to separate left and right textview. At this point the width of the TextView is wrap_content, so if any of the Trxtview content is too large, it will fill the entire parent element.

Or

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/mrelativelayout"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <EditTextAndroid:id= "@+id/input_message"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:hint= "Type Something" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "button" /></LinearLayout>

Remove side element width, left adaptive width.

Layout_weight is calculated in the same way as Flexbox.

Relative layout
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"Android:text= "Button 1" />    <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"Android:layout_alignparenttop= "true"Android:text= "button 2" />    <ButtonAndroid:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_centerinparent= "true"Android:text= "button 3" />    <ButtonAndroid:id= "@+id/button4"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentleft= "true"Android:text= "button 4" />    <ButtonAndroid:id= "@+id/button5"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:layout_alignparentright= "true"Android:text= "button 5"Android:textallcaps= "false" /></Relativelayout>

child controls relative to parent container

Android:layout_alignparentbottom if the value is true, align the bottom of the control with the bottom of the parent control
Android:layout_alignparentleft if the value is true, align the left side of the control with the left side of the parent control
Android:layout_alignparentright if the value is true, align the right side of the control with the right side of the parent control
Android:layout_alignparenttop if the value is true, aligns the top of the space with the top of the parent control
Android:layout_centerhorizontal if the value is true, the control will be in the horizontal direction of the central
Android:layout_centerinparent if the value is true, the control is centered on the horizontal and vertical direction of the parent control
Android:layout_centervertical if the value is true, the control will be in the vertical direction of the central

Child controls relative to applies controls

Android:layout_above above the given ID control
Android:ayout_below under the given ID control
Android:layout_toleftof to the left of the given ID control
Android:layout_torightof to the right of the given ID control
Android:layout_alignbottom aligns with the bottom edge of the given ID control
Android:layout_alignleft aligns with the left edge of the given ID control
Android:layout_alignright aligns to the right edge of the given ID control
Android:layout_aligntop aligns with the top edge of the given ID control

Constrained layout
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.constraint.constraintlayout xmlns:android= "http:/ /schemas.android.com/apk/res/android "Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.thinkpad.testandroid.Main4Activity" > <Button Android:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Demo"/> <Button Android:id= "@+id/button2"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Button2"App:layout_constraintleft_torightof= "@id/button1"/> <Button Android:id= "@+id/button3"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_marginbottom= "20DP"Android:text= "Button3"App:layout_constraintbottom_tobottomof= "Parent"/></android.support.constraint.constraintlayout>

The attribute shape, such as XXX in layout_constraintxxx_toyyyof,constraintxxx, is the side of the child control itself (left, right, Top, Bottom, Baseline, The yyy in toyyyof represents which edge of the constraint control is constrained (the values are left, right, Top, Bottom, Baseline).

For example: app:layout_constraintleft_torightof= "@id/button1", which means that the left side of the control itself is on the right side of Button1; App:layout_constraintleft_tori ghtof= "parent", which means that the bottom of the control itself is aligned with the bottom of the parent control.

Getting Started with Android (i)

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.