實驗三 Android程式設計

來源:互聯網
上載者:User

標籤:XA   網路   1.0   問題   theme   youdao   fail   relative   launch   

實驗三 Android程式設計課程:Java程式設計班級:1652姓名:孔月學號:20165208指導教師:婁嘉鵬實驗日期:2018.5.14實驗名稱:Android程式設計實驗要求:
  1. 沒有Linux基礎的同學建議先學習《Linux基礎入門(新版)》《Vim編輯器》 課程;
  2. 完成實驗、撰寫實驗報告,注意實驗報告重點是運行結果,遇到的問題(工具尋找,安裝,使用,程式的編輯,調試,運行等)、解決辦法(空洞的方法如“查網路”、“問同學”、“看書”等一律得0分)以及分析(從中可以得到什麼啟示,有什麼收穫,教訓等);
  3. 實驗報告中統計自己的PSP(Personal Software Process)時間;
  4. 嚴禁抄襲。

    實驗內容、步驟與體會

目錄:
  • (一)安裝認識Android
  • (二)活動
  • (三)Toast
  • (四)布局測試
  • (五)事件處理測試
(一)安裝認識Android
  • 安裝 Android Stuidio
  • 完成Hello World, 要求修改res目錄中的內容,Hello World後要顯示自己的學號,自己學號前後一名同學的學號
  • 學習Android Stuidio調試應用程式
  • 將activity_main.xml中的android:text="Hello World!"中的Hello World改成"Hello World!20165208\n 20165207\n 20165209\n"
  • 完整代碼如下
<?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=".MainActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Hello World!20165208\n  20165207\n 20165209\n"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent" /></android.support.constraint.ConstraintLayout>
  • 實驗效果如下

返回目錄

(二)活動

  • 構建項目,運行教材相關代碼
  • 建立 ThirdActivity, 在ThirdActivity中顯示自己的學號,修改代碼讓MainActivity啟動ThirdActivity
import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.TextView;public class MainActivity extends Activity implements    OnTouchListener {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TextView tv = (TextView) findViewById(R.id.textView1);        tv.setOnTouchListener(this);    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it// is present.        getMenuInflater().inflate(R.menu.menu_main, menu);        return true;    }    @Override    public boolean onTouch(View arg0, MotionEvent event) {        Intent intent = new Intent(this, ThirdActivity.class);        intent.putExtra("message", "20165208 孔月");        startActivity(intent);        return true;    }}

代碼運行如下

返回目錄

(三)Toast

  • 構建項目,運行教材相關代碼
  • 修改代碼讓Toast訊息中顯示自己的學號資訊
  • 具體代碼如下

activity_main

<?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="com.example.lxkj.commitzyq3.MainActivity">    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="20165230"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toRightOf="parent"        app:layout_constraintTop_toTopOf="parent"        app:layout_constraintHorizontal_bias="0.318"        app:layout_constraintVertical_bias="0.226" />    <Button        android:id="@+id/btn1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        tools:layout_editor_absoluteY="16dp"        tools:layout_editor_absoluteX="5dp" /></android.support.constraint.ConstraintLayout>

MainActivity.java

import android.content.Context;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.app.Activity;import android.util.AttributeSet;import android.view.Menu;import android.view.MenuItem;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);        Button btnshow1=(Button) findViewById(R.id.btn1);        btnshow1.setOnClickListener(new View.OnClickListener()        {            @Override            public void onClick(View v){                Toast toast = Toast.makeText(MainActivity.this,"20165208 孔月", Toast.LENGTH_LONG);                toast.show();            }        });    }

最終運行效果

返回目錄

(四)布局測試

  • 構建項目,運行教材相關代碼
  • 修改布局讓P290頁的介面與教材不同
  • 具體代碼如下

    <RelativeLayoutxmlns: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"android:paddingLeft="2dp"android:paddingRight="2dp"><Button    android:id="@+id/cancelButton"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="20165208"    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></RelativeLayout>
    運行如下

    返回目錄
    (五)事件處理測試
  • 構建項目,運行教材相關代碼
  • 具體代碼如下

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.dell1.helloworld"    android:versionCode="1"    android:versionName="1.0">    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <application        android:allowBackup="true"        android:label="@string/app_name"        android:theme="@style/AppTheme">        <activity            android:name="com.example.dell1.helloworld.MainActivity"            android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

  • 簡要調整後,運行效果
問題總結與體會
  • 問題1:本次實驗安裝Android Stuidio上遇到了很多困難,先是並沒有如老師的步驟所寫的自動彈出sdk安裝介面,但是後續操作中又顯示已經安裝。應該是對安裝過程沒有產生大的影響
  • 問題2:在安裝結束需要安裝外掛程式時,多次點擊try again無任何反應,均顯示failed
  • 解決方案:是最初下載的gradle安裝包有問題,進行替換後即可正常安裝。
  • 問題3:接下來的安裝我遇到了最大的問題,顯示提示無法找到sdk,但是在sdk安裝路徑中我又可以看到它已經安裝並使用,後發現所設定的手機無法使用,具體問題如,在刪去手機重新設定無效後,我上網尋找了問題,網上給出的解決方案如,多次矯正後都無法正確運行,後又卸載安裝了三次還是無法運行,也有詢問過同學助教還是無法解決這個問題。。。

  • 暫時的解決方案:


  • 體會:本次實驗對我來說有點難,從安裝開始遇到問題,這個問題持續到後來也沒有解決,是真的不知道幹怎麼解決了,網上查到的相近的問題解決方案都進行了嘗試,然而並沒有任何效果,也進行了卸載安裝,但是再開啟時還是同樣的問題,於是後來在助教學姐的建議下我選擇了借用同學的電腦完成此次實驗。
步驟 耗時 百分比
需求分析 25 min 8.3%
設計 70 min 23.3%
代碼實現 120 min 40%
測試 40 min 13.3%
分析總結 45 min 15%

實驗三 Android程式設計

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.