实验5:第一个安卓应用

2022年夏季《移动软件开发》实验报告

姓名:窦海彤 学号:20020007011
姓名学号 窦海彤,20020007011
课程 中国海洋大学22夏《移动软件开发》
实验名称 实验5:第一个安卓应用
博客地址 https://www.cnblogs.com/dht21/
Github仓库地址 https://github.com/Domingo21/summer-term

一、实验目标

​ 1. 模仿微信“发现”页创建列表布局

​ 2. 学习使用Textview imageview、LinearLayout

二、实验步骤

1. 环境配置

需要配置Java环境和Android studio环境

Java环境配置:https://www.cnblogs.com/renqiqiang/p/6822143.html

Android studio环境配置:https://www.cnblogs.com/renqiqiang/p/6822143.html

2. 项目创建

选择新项目

选择空项目

选择语言为Java,以及和手机Android版本相同的版本

将此处切换为project

打开activity_main.xml文件

3. 编写代码

在一个组件中写一栏

<LinearLayout
    android:background="#fff"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="60dp">

    <ImageView
        android:layout_marginLeft="15dp"
        android:layout_gravity="center_vertical"
        android:background="@mipmap/icon_pengyou"
        android:layout_width="40dp"
        android:layout_height="40dp"/>
    <TextView
        android:layout_marginLeft="10dp"
        android:textStyle="bold"
        android:textColor="#333"
        android:textSize="18dp"
        android:gravity="center_vertical"
        android:layout_weight="1"
        android:text="朋友圈"
        android:layout_width="0dp"
        android:layout_height="match_parent"/>
    <ImageView
        android:layout_marginRight="15dp"
        android:layout_gravity="center_vertical"
        android:background="@mipmap/right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

以此类推,写出其余部分,其中,灰色的分割部分利用android:layout_marginTop="10pt"来空出

完整代码:

<?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="#e5e5e5"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/icon_pengyou"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="朋友圈"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="10pt">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/yao"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="摇一摇"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/sao"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="扫一扫"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="10pt">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/kan"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="看一看"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/sou"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="搜一搜"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="10pt">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/gou"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="购物"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/you"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="游戏"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="10pt">

        <ImageView
            android:layout_marginLeft="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/xiao"
            android:layout_width="40dp"
            android:layout_height="40dp"/>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="小程序"
            android:layout_width="0dp"
            android:layout_height="match_parent"/>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>

</LinearLayout>

三、运行截图

四、问题总结与体会

​ 通过本次实验,我熟悉了Java环境配置,以及用Android studio开发Android app的过程,通过模仿写微信的发现页面,我熟悉了Textview、imageview、LinearLayout的使用

posted @ 2022-08-24 16:20  Domingo  阅读(55)  评论(0编辑  收藏  举报