• 学号20192314 2020-2021-1 《数据结构与面向对象程序设计》实验五报告


    1.Android Stuidio的安装测试:

    参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:

    参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio

    完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分

    学习Android Stuidio调试应用程序

    1.Mainactivity

    import androidx.appcompat.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);
    }
    

    }

    2.activity_main

      <?xml version="1.0" encoding="utf-8"?>
     <androidx.constraintlayout.widget.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">
    
    <TextView
        android:layout_width="190dp"
        android:layout_height="133dp"
        android:text="Hello World!于鲲洋20192314 
    前一人20192313 
    后一人20192315"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    
     </androidx.constraintlayout.widget.ConstraintLayout>
    

    3.运行截图


    2.Activity测试

    参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:

    构建项目,运行教材相关代码

    创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity

    1.代码

    import androidx.appcompat.app.AppCompatActivity;

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

    public class MainActivity extends AppCompatActivity {

    private Button Go;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Go = findViewById(R.id.textGo);
        Go.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到ThirdActivity演示界面
                Intent intent = new Intent(MainActivity.this, ThirdActivity.class);
                startActivity(intent);
            }
        });
    }
    

    }

    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class ThirdActivity extends AppCompatActivity {
    
       private TextView textView;
    
       @Override
        protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_third);
           textView = findViewById(R.id.textGo);
    }
    

    }

    2.运行截图



    3.UI测试

    参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:

    构建项目,运行教材相关代码

    修改代码让Toast消息中显示自己的学号信息

    1.程序代码

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.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">
    
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="呵呵"
        android:textColor="#FFFFFF"
        android:textSize="72sp"
        app:backgroundTint="#D13B3B"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    textView.setTextSize(500);
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        //在onCreat中设置一个Button类的对象bt,并用findViewById将它指向我们在布局中创建好的button
        Button bt=(Button)findViewById(R.id.button1);
    
        //调用Button类的setOnClickListener方法来创建一个监听器
        bt.setOnClickListener(new View.OnClickListener() {
    
            //重写onClick方法来定义点击button后的活动
            @Override
            public void onClick(View v) {
    
                //直接用Toast和它的makeText方法来创建一个Toast弹窗
                Toast.makeText(MainActivity.this,"20192314于鲲洋",Toast.LENGTH_SHORT).show();
            }
        });
    }
    

    }

    2.运行截图


    4.布局测试:

    参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android ###2nd)》第二十七章:

    构建项目,运行教材相关代码

    修改布局让P290页的界面与教材不同

    运行截图



    5.事件处理测试:

    参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android ###2nd)》第二十八章:

    构建项目,运行教材相关代码

    提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

    1.程序代码

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Text5">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="201dp"
        android:layout_height="175dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="485dp"
        android:onClick="changeColor" />
    
    ####2.运行截图 ![](https://img2020.cnblogs.com/blog/2147066/202011/2147066-20201104221528957-1310067509.jpg) ![](https://img2020.cnblogs.com/blog/2147066/202011/2147066-20201104221534143-1912016934.jpg) #遇到的问题 ###1.AS中的虚拟设备在下载之后依然无法使用,最终选择在网络上搜索教程,将手机连接到电脑上,打开USB调试,直接在手机上进行实验 ###2.有时候手机应用中无法显示文件的名字,发现当继承的不是AppCompatActivity类而是Activity类,不会显示应用名称。使MainActivity继承AppCompatActivity类即可 #心得体会 ###Android第一次做实验,基本上啥也不会,打开之后那么多文件总共就认得出一个java文件,其余的无论是用途还是语法完全没见过。单是前期调试虚拟设备就让我十分崩溃,下载不断失败,不断retry,最终下好之后发现还是用不了,不得已尝试着将真手机连接在电脑上,勉强将实验进行下去了。Andriod比我想象的复杂的多,很多知识还需要在今后不断学习不断巩固。
  • 相关阅读:
    ping-tool
    yum 安装 5.6
    音视频编辑
    图表
    VC2013设置输出文件目录
    hdu 4679 Terrorist’s destroy 树形DP
    poj 3580 SuperMemo splay tree(重口味)
    hdu 1890 Robotic Sort splaytree+懒惰标记
    bzoj 1588 [HNOI2002]营业额统计 splay tree
    bzoj 1503 [NOI2004]郁闷的出纳员 splay tree
  • 原文地址:https://www.cnblogs.com/yukunyang/p/13929126.html
Copyright © 2020-2023  润新知