2018-2019-2 20175227張雪瑩《Java程序設計》實驗四 《Android程序設計》

2018-2019-2 20175227張雪瑩《Java程序設計》

實驗四 《Android程序設計》

實驗報告封面

  • 課程:Java程序設計 班級:1752班 姓名:張雪瑩 學號:20175227
  • 指導教師:婁嘉鵬 實驗日期:2019年5月13日
  • 實驗時間:--- 實驗序號:實驗四
  • 實驗名稱:Android程序設計
  • 實驗題目
  • 實驗要求
    • 參考Android開發簡易教程
    • 完成雲班課中的檢查點,也能夠先完成實驗報告,直接提交。注意不能只有截圖,要有知識點,原理,遇到的問題和解決過程等說明。實驗報告中一個檢查點要有多張截圖。
    • 發表實驗報告博客,標題「學期(如2018-2019-2) 學號(如20175300) 實驗四《Android開發基礎》實驗報告」

實驗步驟

  • Android Studio 的安裝測試
    • 要求:
      • 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調試應用程序
    • 實現過程:
      • 再佈局文件activity_main.xml中,經過Common Attributes->text內容改成Hello World! 20165318 20165317 20165319
      • 也能夠在代碼中修改第十二行代碼爲:android:text="Hello World!20175227 20175226 20175228"
        如圖

  • Activity測試
    • 要求:
      • 參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
      • 構建項目,運行教材相關代碼
      • 建立 ThirdActivity, 在ThirdActivity中顯示本身的學號,修改代碼讓MainActivity啓動ThirdActivity
      • 提交代碼運行截圖和碼雲Git連接,截圖要有學號水印,不然會扣分
    • 實現過程
      • 選中Java文件夾下的目錄文件->File->New->Activity->Empty Activity,新建一個activity,對其命名爲:ThirdActivity,單擊finish

  • MainActicity.java中增長包package com.example.helloworld;並增長代碼:html

    Intent intent = new Intent(this,ThirdActivity.class);
     startActivity(intent);
    • 運行結果爲:

  • UI測試
    • 要求
      • 參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
      • 構建項目,運行教材相關代碼
      • 修改代碼讓Toast消息中顯示本身的學號信息
      • 提交代碼運行截圖和碼雲Git連接,截圖要有學號水印,不然會扣分
    • 實現過程
      • 在MainActivity.java中增長以下代碼:
      Toast toast=Toast.makeText(MainActivity.this, "20175227張雪瑩",Toast.LENGTH_LONG);
       toast.show();
      如圖:

  • 運行結果:

  • 佈局測試
    • 要求
      • 參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
      • 構建項目,運行教材相關代碼
      • 修改佈局讓P290頁的界面與教材不一樣
      • 提交代碼運行截圖和碼雲Git連接,截圖要有學號水印,不然會扣分
    • 佈局的類型
      • 線性佈局LinearLayout:線性佈局是一個視圖組(ViewGroup),能在水平或者垂直的單一方向上將全部子元素排成一行
      • 相對佈局RelativeLayout:相對佈局是一個將子視圖顯示在相對的位置上的佈局
      • 表格佈局TableLayout:表格佈局是在行、列中組合子元素的視圖
      • 絕對佈局AbsoluteLayout:絕對佈局能讓你指定子元素的精確位置
      • 幀佈局FrameLayout:幀佈局是一個屏幕上的佔位符,你能夠用它來顯示單一視圖
      • 列表視圖ListView:列表佈局是能夠滾動的,是用於顯示子元素列表的視圖組
      • 網格視圖GridView:網格視圖是在二維可滾動的網格中顯示子元素的視圖組
    • 代碼爲:
<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="20175227"
        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"
            android:text="Share" />
        <Button
            android:id="@+id/deleteButton"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Delete" />
    </LinearLayout>

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="160dp"
        app:srcCompat="@mipmap/ic_launcher" />
</RelativeLayout>
  • 運行結果:

  • 事件處理測試
    • 要求
      • 參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
      • 構建項目,運行教材相關代碼
      • 提交代碼運行截圖和碼雲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="20175227張雪瑩"
        android:layout_marginLeft="70dp"
        android:layout_marginTop="300dp"
        android:textSize="21dp"/>
</RelativeLayout>
  • 運行結果:

實驗中遇到的問題和解決過程

  • 問題1:在運行MainActivity.java時,老是出錯,根據提示猜想多是聯網失敗、Intel x86的某個包未下載,排除以上緣由後仍是沒法運行。

  • 問題1解決辦法:嘗試自行修改了settings目錄下的兩處,如圖


下載了兩個SDK Platformjava


取消了上面的勾選android

程序正確運行,如圖:git

代碼託管

參考資料

  • https://zhinan.sogou.com/guide/detail/?id=316513750890
  • https://www.cnblogs.com/sunxiaoxuan/p/9061472.html#8
  • https://www.cnblogs.com/besty-zyx/p/9060556.html
  • http://www.cnblogs.com/ludashi/p/4883915.html
相關文章
相關標籤/搜索