Detailed usage of four Andriod layouts

Strongly Recommend Articles: Welcome to Collection
Android Dry Goods Sharing

Read for five minutes, ten o'clock a day, and study with you for life. Here's Android, a programmer.

This article mainly introduces some knowledge points in Android development. By reading this article, you will gain the following contents:

  1. Linear Layout Linear Layout
  2. Relative Layout Relational Layout
  3. FrameLayout Frame Layout
  4. Table Layout table layout

In Android, where there is an interface, there is a layout, which is very important for Android. Four common layouts in Android: Linear Layout, Relative Layout, Frame Layout and Table Layout.

Absolute Layout has been discarded. This question is omitted.

1.LinearLayout

Linear layout, one of the common Android layouts, mainly includes horizontal layout and vertical layout. Horizontal layout of linear layout is mainly distinguished by orientation attribute. Vertical layout: android:orientation="vertical". Horizontal layout:
2.android:orientation="horizontal".
## Linear Layout Inheritance Relation

java.lang.Object
   ↳    android.view.View
        ↳    android.view.ViewGroup
             ↳    android.widget.LinearLayout

A simple example of Linear Layout

The layout code is implemented as follows:

 <LinearLayout
        android:id="@+id/ll_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@android:color/holo_purple"
                android:gravity="center_horizontal"
                android:padding="10dp"
                android:text="Horizontal layout" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@android:color/holo_green_light"
                android:gravity="center_horizontal"
                android:padding="10dp"
                android:singleLine="true"
                android:text="Horizontal layout" />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/holo_orange_light"
            android:gravity="center_horizontal"
            android:padding="10dp"
            android:text="Vertical layout" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_light"
            android:gravity="center_horizontal"
            android:padding="10dp"
            android:text="Vertical layout" />
    </LinearLayout>

2. RelativeLayout

Relational Layout: Relative Layout, one of Android's commonly used layouts, is mainly more relative to placement controls, such as: left, center, right.

Inheritance:

java.lang.Object
   ↳    android.view.View
        ↳    android.view.ViewGroup
             ↳    android.widget.RelativeLayout
  • A simple example of Relative Layout

  • The static code layout is as follows:
    <RelativeLayout
        android:id="@+id/rl_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tittle_bg"
        android:padding="10dp"
        android:visibility="gone" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:drawableLeft="@drawable/arrow_pressed"
            android:drawablePadding="5dp"
            android:text="dynamic" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="Friend dynamics" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/tittle_add" />
    </RelativeLayout>

3. FrameLayout

FrameLayout: One of Android's most common layouts is to lay out by frame. Controls are superimposed and subsequent layouts cover previous layouts.

The FrameLayout inheritance relationship is as follows:

java.lang.Object
   ↳    android.view.View
        ↳    android.view.ViewGroup
             ↳    android.widget.FrameLayout

Simple FrameLayout example

  • The layout implementation code is as follows:
 <FrameLayout
        android:id="@+id/fl_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" >

        <TextView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_gravity="center"
            android:background="@android:color/holo_orange_light"
            android:gravity="center_vertical"
            android:text="  1"
            android:textColor="@android:color/black" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:background="@android:color/holo_green_light"
            android:gravity="center_horizontal"
            android:text="2" />

        <TextView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:background="@android:color/holo_blue_bright"
            android:gravity="center"
            android:text="3" />
    </FrameLayout>

4. Table Layout table layout

TableLayout table layout: One of the most common layouts in Android, this layout is used to achieve similar table effects.

TableLayout Inheritance

TableLayout inherits LinearLayout, and the relationship is as follows:

java.lang.Object
   ↳    android.view.View
        ↳    android.view.ViewGroup
             ↳    android.widget.LinearLayout
                  ↳    android.widget.TableLayout

Simple 2*2 cases are as follows:

  • The layout implementation code is as follows:
 <TableLayout
        android:id="@+id/tl_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone" >

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@android:color/holo_green_light"
                android:gravity="left"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="WeChat Number:" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@android:color/holo_blue_bright"
                android:gravity="center"
                android:paddingBottom="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp"
                android:text="ProgramAndroid" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp" >

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@android:color/holo_blue_bright"
                android:gravity="left"
                android:paddingBottom="10dp"
                android:paddingLeft="10dp"
                android:paddingTop="10dp"
                android:text="Wechat Public Number:" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_weight="1"
                android:background="@android:color/holo_green_light"
                android:gravity="center"
                android:paddingBottom="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp"
                android:text="Programmer Android" />
        </TableRow>
    </TableLayout>

So far, this article is over. If there are any mistakes, you are welcome to make suggestions and corrections. At the same time look forward to your attention, thank you for reading, thank you!

Keywords: Android Java Attribute

Added by nikkio3000 on Mon, 05 Aug 2019 14:15:01 +0300