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