Android进阶之路Android开发Android技术知识

Android应用开发笔记之线性布局LinearLayout(二

2019-07-03  本文已影响2人  Lee_5566
image.png

目录

第一篇:Android应用开发笔记之Android Studio第一个程序(一)
第二篇:Android应用开发笔记之线性布局LinearLayout(二)
第三篇:Android应用开发笔记之线性布局LinearLayout(二)小练习

七色板

使用线性布局构建七色板,首先查看下配色表,这其中颜色的编码是多少:

颜色 编码
android:background="#FF0033"
android:background="#FFCC33"
android:background="#FFFF00"
绿 android:background="#00CC00"
android:background="#0066CC"
android:background="#6666CC"
android:background="#993399"

activity_main.xml文件里主要为:

<?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=".MainActivity">

    <LinearLayout
        android:id="@+id/linearLayout11"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#FF0033"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#FFCC33"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#FFFF00"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#00CC00"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout5"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#0066CC"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout6"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#6666CC"></LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout7"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:background="#993399"></LinearLayout>
    </LinearLayout>

</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"

xmlns:android和xmlns:tools指定的是xml文件的命名空间,不是对布局的主要设置.

 android:layout_width="match_parent"

用于指定当前的线性布局宽度占整个父元素,这里相对于当前的线性布局父元素为当前的窗体,所以宽度占满窗体

android:layout_height="match_parent"

用于指定当前的线性布局高度占整个父元素,这里相对于当前的线性布局父元素为当前的窗体,所以高度占满窗体

tools:context="com.example.activitylife.MainActivity"

用于指定渲染上下文

android:orientation="vertical"

用于指定当前控件为垂直摆放

android:background="#993399"

用于指定背景色

生成的效果

image.png

虚拟机运行结果

image.png

好了打完收工,回去睡觉.O(∩_∩)O

参考

Android的学习第六章(布局一LinearLayout)
网页设计常用色彩搭配表
《配色表》

上一篇 下一篇

猜你喜欢

热点阅读