zoukankan      html  css  js  c++  java
  • 20175212童皓桢 实验四 Android程序设计

    20175212童皓桢 实验四 Android程序设计

    实验内容

    • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》并完成相关学习

    实验步骤

    一、Android Stuidio的安装测试

    任务一要求:

    • 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装Android Stuidio
    • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号
    • 学习Android Stuidio调试应用程序

    实验过程:

    • 将MainActivity.java中,选择text界面,将android:text="Hello World!"修改为
    android:text="Hello World20175212 20175211 20175213!"
    

    输入图片说明

    • 将MainActivity.java中,选择design图形界面,选中中间的文本框进行编辑,输入
    "Hello World20175212 20175211 20175213!"
    

    输入图片说明

    • 运行结果:
      输入图片说明

    二、Activity测试

    任务二要求:

    • 构建项目,运行教材相关代码
    • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
    • 提交代码运行截图和码云Git链接
      实验过程
    1. MainActivity相同的目录下创建ThirdActivity项目
    2. 按照修改MainActivity中相关代码
    3. 修改在layout中activity_third.xml文件,具体是
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20175212童皓桢" />
    
    -	MainActivity.java
    package com.example.helloworld;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Intent intent = new Intent(this,ThirdActivity.class);
            startActivity(intent);
    
        }
    }
    
    -	Activity_third.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=".ThirdActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20175212童皓桢" />
    
    </android.support.constraint.ConstraintLayout>
    
    

    运行结果:
    输入图片说明

    三、UI测试

    任务三要求:

    • 构建项目,运行教材相关代码
    • 修改代码让Toast消息中显示自己的学号信息
    • 提交代码运行截图和码云Git链接
    • MainActivity.java
    package com.example.helloworld;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Toast toast=Toast.makeText(MainActivity.this, "20175212童皓桢", Toast.LENGTH_LONG);
            toast.show();
    
        }
    }
    
    

    运行结果:
    输入图片说明

    四、布局测试

    任务四要求:

    • 构建项目,运行教材相关代码
    • 修改布局让P290页的界面与教材不同
    • 提交代码运行截图和码云Git链接,截图要有学号水印
    • activity_main.xml
    <RelativeLayout
        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:paddingLeft="2dp"
        android:paddingRight="2dp">
        <Button
            android:id="@+id/cancelButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20175212"
            android:layout_marginTop="70dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />
        <Button
            android:id="@+id/saveButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="童皓桢"
            android:layout_below="@+id/cancelButton"
            android:layout_alignLeft="@+id/cancelButton"
            android:layout_alignStart="@+id/cancelButton"
            android:layout_marginTop="23dp" />
        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginTop="45dp"
            android:padding="4dp"
            android:src="@android:drawable/ic_dialog_email"
            android:id="@+id/imageView"
            android:layout_below="@+id/saveButton"
            android:layout_centerHorizontal="true" />
        <LinearLayout
            android:id="@+id/filter_button_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center|bottom"
            android:background="@android:color/white"
            android:orientation="horizontal" >
            <Button
                android:id="@+id/filterButton"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="Filter" />
            <Button
                android:id="@+id/shareButton"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                and
    
    

    运行结果:

    输入图片说明

    五、事件处理测试

    • 构建项目,运行教材相关代码
    • 提交代码运行截图和码云Git链接,截图要有学号水印
    • activity_main.xml
    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout
    
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
        <AnalogClock
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="90dp"
            android:id="@+id/analogClock1"
            android:onClick="changeColor" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="20175212 童皓桢"
            android:layout_marginLeft="60dp"
            android:layout_marginTop="300dp"
            android:textSize="16dp"/>
    </RelativeLayout>
    
    

    运行结果:

    输入图片说明

    实验中遇到的问题

    • 问题一:Android Studio中出现Java未识别文件,并且无法正常编译运行。(类名前为红J)

    输入图片说明

    • 解决办法一:在左边目录中找到build.gradle文件,点击Sync Project with Gradle File。或者参考https://www.cnblogs.com/kissfu/p/6093335.html添加代码,即可解决。
      输入图片说明

    参考博客

    https://www.cnblogs.com/kissfu/p/6093335.html

  • 相关阅读:
    Python的学习之旅———UDP
    Python的学习之旅———socket ,socketserver
    Python的学习之旅———time 模块
    python的学习之旅---面向对象
    Python的学习之旅———re 模块正则表达式
    有事没事找高宇哥聊天,李泽军爸妈聊天,管那么多人干嘛,活好自己
    还有教师观没有记
    Navicat中怎么查看数据库密码
    Oracle 删除用户时出现异常ora-01922: CASCADE must bu specified to drop 用户名
    kali使用sqlmap注入dvma
  • 原文地址:https://www.cnblogs.com/thz666/p/10879283.html
Copyright © 2011-2022 走看看