LinearLayout and linearlayout in Android

Source: Internet
Author: User

LinearLayout and linearlayout in Android
LinearLayout: Linear Layout

In general, when many controls need to be listed on an interface, we can use LinearLayout (Vertical) Or horizontal direction (Horizontal), Sort the sub-elements in sequence, and each sub-element is located after the previous element. Let's take a look at it briefly.

In the XML layout file, the following units are displayed:

Px: Is the screen pixel dp: an abstract unit based on density. The physical size of the screen sp: is similar to that of dp, but is scaled according to the user's font size.

The XML Code is as follows: Change android: orientation = "vertical" vertical direction (Vertical)

<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Xmlns: tools = "http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical"
Tools: context = "com. example. administrator. adapter. MainActivity">
<TextView
Android: text = "first TextView"
Android: background = "# ef0808"
Android: gravity = "center"
Android: textSize = "18sp"
Android: layout_width = "match_parent"
Android: layout_height = "100dp"/>
<TextView
Android: text = "second TextView"
Android: gravity = "center"
Android: background = "# 31ef0b"
Android: textSize = "18sp"
Android: layout_width = "match_parent"
Android: layout_height = "100dp"/>
<TextView
Android: text = "third TextView"
Android: gravity = "center"
Android: textSize = "18sp"
Android: background = "# ec07ca"
Android: layout_width = "match_parent"
Android: layout_height = "100dp"/>
<TextView
Android: text = "fourth TextView"
Android: gravity = "center"
Android: textSize = "18sp"
Android: background = "# f5d105"
Android: layout_width = "match_parent"
Android: layout_height = "100dp"/>
</LinearLayout>
Running result: Each TextView is arranged from top to bottom.

 

The XML Code is as follows: Change android: orientation = "horizontal" horizontal Direction (Horizontal)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "horizontal"
Tools: context = "com. example. administrator. adapter. MainActivity">
<TextView
Android: text = "first TextView"
Android: background = "# ef0808"
Android: gravity = "center"
Android: textSize = "18sp"
Android: layout_width = "100dp"
Android: layout_height = "100dp"/>
<TextView
Android: text = "second TextView"
Android: gravity = "center"
Android: background = "# 31ef0b"
Android: textSize = "18sp"
Android: layout_width = "100dp"
Android: layout_height = "100dp"/>
<TextView
Android: text = "third TextView"
Android: gravity = "center"
Android: textSize = "18sp"
Android: background = "# ec07ca"
Android: layout_width = "100dp"
Android: layout_height = "100dp"/>
<TextView
Android: text = "fourth TextView"
Android: gravity = "center"
Android: textSize = "18sp"
Android: background = "# f5d105"
Android: layout_width = "100dp"
Android: layout_height = "100dp"/>
</LinearLayout>

Running result: Each TextView is arranged horizontally from left to right.

The only difference between the two linear la s is that the value of android: orientation is different.

Experiment conclusion: the only difference between the two linear la s is that the android: orientation values are different. This experiment provides a preliminary understanding of the linear la s in Android.


Author: bigboss bit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.