Android学习记录(一)

Android学习记录(1)

本次文章记录了我第一次开始学习安卓所做出的一些界面,由于是第一次做得到十分美观的结果,但是也获得了一些有效的成果。

1.Android的相关介绍

在进行新的学习内容之前,我们需要了解该门课程的一些相关内容

1.1Android是什么

Android是一种基于Linux的开源的操作系统。
主要用于智能设备,如智能手机、平板电脑和智能电视等。
由Google公司领头开发并推广,2008年推出第一个版本。
此系统最初由“安卓之父”Andy Rubin(安迪-鲁宾)开发(2003年)。

1.2使用工具(Android Studio)

Android Studio 是谷歌推出的一个Android集成开发工具,基于IntelliJ IDEA. 类似 Eclipse ADT,Android Studio 提供了集成的 Android 开发工具用于开发和调试。

在Android Studio中我们一共包含三种视图,分别是Project视图、Package视图和Android视图。
1.Android视图
Android视图
2.Project视图
Project视图
3.Packags视图
Packages视图

1.3Android应用目录结构

在Android视图查看安卓应用目录结构,有manifests、java和res三个重要目录。其中manifests为项目清单目录,java为JAVA源程序目录,res为资源目录。

2.Android案例(一)

再通过对所学习知识有了初步了解后,我打算通过制作一个案例来进行更加深层次的学习。

为了更加了解线性布局的使用方法,我便使用入门级的线性布局的方法完成了第一个任务。
完成效果如图所示:
在这里插入图片描述
完成思路:首先,为了达到该效果,我将整体划分为两个部分,首先在第一部分我将图片设置为上半部分的背景,在第二部分,我使用了另一个线性布局,并在其中插入了两个文本框并设置圆角矩形,以及一个按钮。

相关文件主要代码如下:
1.activity_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/background"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bluelogo"
            android:layout_gravity="bottom" />


    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:background="#c0c0c0"
        android:gravity="center"
        android:orientation="vertical">


        <EditText
            android:id="@+id/editText01"
            android:layout_width="380dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:height="8dp"
            android:background="@drawable/editsharp"
            android:drawableLeft="@drawable/logo3"
            android:drawablePadding="10dp"
            android:ems="5"
            android:inputType="textImeMultiLine"
            android:lines="2"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbars="vertical"
            android:text="@string/username"
            android:textColor="#708090" />

        <EditText
            android:id="@+id/editText02"
            android:layout_width="380dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:height="8dp"
            android:background="@drawable/editsharp"
            android:drawableLeft="@drawable/logo4"
            android:drawablePadding="10dp"
            android:ems="5"
            android:inputType="textImeMultiLine"
            android:lines="2"
            android:paddingTop="1dp"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbars="vertical"
            android:text="@string/password"
            android:textColor="#708090" />

        <Button
            android:layout_width="380dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:id="@+id/btnLogin"
            android:layout_gravity="center"
            android:text="登录"
            android:textColor="@color/white"
            android:background="#330066"/>


    </LinearLayout>


</LinearLayout>

2.圆角矩形实现代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--<gradient
        android:angle="45"
        android:endColor="#cccccc"
        android:startColor="#cccccc"/>-->

    <padding
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp"/>
    <!--设置圆角矩形-->
    <corners android:radius="3dp"/>

    <stroke
        android:color="@color/white"
        android:width="25px"/>
    <solid android:color="@color/white"/>
</shape>

3.Android案例(二)

在进行线性布局的案例完成后,我同样也实现了网格布局的案例完成,虽然效果的展现不是很美观,但是也是初学者的经历。案例(二)的完成效果如图所示:
在这里插入图片描述
在该项案例中我们同样使用到了圆角矩形,所使用方法与案例(一)大体相同。
案例(二)完成思路:首先,我们将整体插入背景,并向其中进行其他内容的添加。

完成相关主要代码如下:
1.activity_main.xml文件


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background="@drawable/background"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="360dp"
        android:layout_height="30dp"
        android:layout_marginTop="155dp"
        android:layout_gravity="center"
        android:alpha="0.8"
        android:background="@drawable/shape_round_coener"
        android:gravity="center">

        <TextView
            android:layout_width="120dp"
            android:layout_height="30dp"
            android:background="@drawable/shape_round_coener01"
            android:textColor="@color/white"
            android:text="@string/part01"
            android:layout_marginLeft="1dp"
            android:gravity="center"
            android:layout_gravity="left"/>

        <TextView
            android:layout_width="120dp"
            android:layout_height="30dp"
            android:background="@drawable/shape_round_coener"
            android:textColor="#000066"
            android:gravity="center"
            android:text="@string/part02"
            android:layout_gravity="center"/>
        <TextView
            android:layout_width="120dp"
            android:layout_height="30dp"
            android:background="@drawable/shape_round_coener"
            android:text="@string/part03"
            android:textColor="#000066"
            android:gravity="center"
            android:layout_gravity="right"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="12dp"
        android:layout_height="10dp"
        android:background="@drawable/logo"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="80dp"/>

    <GridLayout
        android:layout_width="360dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"

        android:columnCount="3"
        android:rowCount="4">

        <LinearLayout
            android:layout_width="220dp"
            android:layout_height="84dp"
            android:layout_columnSpan="2"
            android:layout_gravity="fill"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc1" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="0"
            android:layout_column="2"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"

                android:background="@drawable/pc2" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="1"
            android:layout_column="0"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc3" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="1"
            android:layout_column="1"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc4" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="1"
            android:layout_column="2"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc5" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="2"
            android:layout_column="0"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc6" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="2"
            android:layout_column="1"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc7" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="2"
            android:layout_column="2"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc8" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="3"
            android:layout_column="0"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc9" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="3"
            android:layout_column="1"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc10" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="107dp"
            android:layout_height="84dp"
            android:layout_row="3"
            android:layout_column="2"

            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"

            android:layout_marginBottom="5dp"
            android:background="@drawable/shape_round_coener02"
            android:gravity="center">

            <ImageView
                android:layout_width="55dp"
                android:layout_height="55dp"
                android:background="@drawable/pc11" />
        </LinearLayout>
    </GridLayout>

    <LinearLayout
        android:layout_width="405dp"
        android:layout_height="170dp"
        android:background="@color/white"
        android:gravity="top"
        >
        <LinearLayout
            android:layout_width="135dp"
            android:layout_height="20dp"
            android:gravity="center"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/logo1"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="首页"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="135dp"
            android:layout_height="20dp"
            android:gravity="center"
            >
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/logo2"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="消息"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="135dp"
            android:layout_height="20dp"
            android:gravity="center"
            >
            <ImageView
                android:layout_width="21dp"
                android:layout_height="20dp"
                android:layout_gravity="center"
                android:src="@drawable/logo3"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="个人中心"/>
        </LinearLayout>

    </LinearLayout>



</LinearLayout>

猜你喜欢

转载自blog.csdn.net/weixin_46705517/article/details/112347219