image.png
使用线性布局构建七色板,首先查看下配色表,这其中颜色的编码是多少:
颜色 | 编码 |
---|---|
赤 | 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