Android Basic layout

Source: Internet
Author: User

First type: linear layout

This layout is relatively simple, either vertically or horizontally.

[HTML]View Plaincopy
  1. <?xml version= "1.0" encoding= "Utf-8"?>
    <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
    Android:layout_width= "Match_parent"
    android:layout_height= "Match_parent"
    android:orientation= "Vertical"
    android:padding= "10DP" >
    <textview
    Android:id= "@+id/text"
    Android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content"
    android:text= "@string/type"/>
    <edittext
    Android:id= "@+id/et_entry"
    Android:layout_width= "Match_parent"
    android:layout_height= "Wrap_content"
    android:hint= "@string/hello"
    android:background= "#ffffff"/>
    <button
    Android:id= "@+id/ok"
    Android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content"
    android:text= "@string/ok"/>
    <button
    Android:id= "@+id/cancel"
    Android:layout_width= "Wrap_content"
    android:layout_height= "Wrap_content"
    android:text= "@string/cancel"/>
    </LinearLayout>

The effect is as follows:

The second type: relative layout

Relative layout: In contrast to a reference position, you must have a reference before you can determine the position of the next control, such as a first, and then B relative to a, on the right, bottom, or position of a. Of course, Android can also be relative to the parent form.

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android" 2 Xmlns:tools= "Http://schemas.android.com/tools" 3 Android:layout_width= "Match_parent" 4 Android:layout_height= "100DP" 5 Tools:context=". Mainactivity "> 6 <TextView7 Android:id= "@+id/tv_title" 8 Android:layout_width= "Wrap_content" 9 Android:layout_height= "Wrap_content" Ten Android:layout_marginleft= "10DP" One Android:layout_margintop= "10DP"  A Android:textcolor= "#660000" - android:textsize= "20SP" - Android:text= "I am the big text" />  the <TextView - Android:layout_below= "@id/tv_title"  - Android:layout_width= "Wrap_content"  - Android:layout_height= "Wrap_content"  + Android:layout_marginleft= "10DP"  - Android:layout_margintop= "10DP"  + Android:textcolor= "#660000"  A android:textsize= "14SP"  at Android:text= "I am a small text" />  - <CheckBox - Android:layout_width= "Wrap_content"  - Android:layout_height= "Wrap_content"  - Android:layout_alignparentleft= "true"  - android:layout_centervertical= "true" in /> - </Relativelayout>

This layout looks like this:

The third type: Table layout

[HTML]View Plaincopy

Table layout: For example, a few rows of columns of formatting, such as what Excel looks like

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <tablelayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="#000000"
  6. android:stretchcolumns="1" >
  7. <TableRow >
  8. <TextView
  9. android:text="name"
  10. android:padding="10dip"
  11. android:textcolor="#ffffff"/>
  12. <EditText
  13. android:layout_marginleft="20DP"
  14. android:background="#ffffff"
  15. />
  16. </TableRow>
  17. <TableRow >
  18. <TextView
  19. android:text="password"
  20. android:padding="10dip"
  21. android:textcolor="#ffffff"/>
  22. <EditText
  23. android:layout_marginleft="20DP"
  24. android:background="#ffffff"
  25. android:password="true"
  26. />
  27. </TableRow>
  28. </tablelayout>

The effect is as follows:



Fourth type: Frame layout

Frame layout: In fact, a relatively simple understanding is that a picture superimposed on the top of a picture, is the picture overlay

[HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <framelayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. >
  6. <TextView
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:layout_gravity="center"
  10. android:background="#ff0000" />
  11. <TextView
  12. android:layout_width="250DP"
  13. android:layout_height="390DP"
  14. android:layout_gravity="center"
  15. android:background="#dd0000" />
  16. <TextView
  17. android:layout_width="180DP"
  18. android:layout_height="300DP"
  19. android:layout_gravity="center"
  20. android:background="#bb0000" />
  21. <TextView
  22. android:layout_width="110DP"
  23. android:layout_height="210DP"
  24. android:layout_gravity="center"
  25. android:background="#990000" />
  26. <TextView
  27. android:layout_width="40DP"
  28. android:layout_height="120DP"
  29. android:layout_gravity="center"
  30. android:background="#770000" />
  31. </framelayout>

The effect is as follows:

Well, hit the common layout of the introduction is over, these are also in the process of looking at the code to find out, I hope to their own, will help others

Android Basic layout

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.