debug run
,程序就會運行在斷點位置處中止在下方debug窗口能夠看到詳細的參數信息
java
點開Run
能夠看到相似於IDEA的調試方法和快捷鍵
android
嘗試Step Over
git
參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章: - 構建項目,運行教材相關代碼app
<Button android:id="@+id/btnSimpleToast" android:layout_width="0dp" android:layout_height="wrap_content" android:text="hey!20175234" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/>
修改MainActivity.java代碼,以下less
package com.example.basiccomponents; import android.support.v7.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); Button btnshow1 = (Button) findViewById(R.id.btnSimpleToast); btnshow1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast toast = Toast.makeText(MainActivity.this, "20175234 趙詩玥", Toast.LENGTH_LONG); toast.show(); } }); } }
運行結果截圖以下ide
佈局測試: 參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章: - 構建項目,運行教材相關代碼佈局
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="20175217wyf" android:layout_marginLeft="70dp" android:layout_marginTop="300dp" android:textSize="38dp" android:textColor="#bbbb00"/> </RelativeLayout>
MainActivity測試
package com.example.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.AnalogClock; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.AnalogClock; public class MainActivity extends Activity { int counter = 0; int[] colors = { Color.BLACK, Color.BLUE, Color.CYAN, Color.DKGRAY, Color.GRAY, Color.GREEN, Color.LTGRAY, Color.MAGENTA, Color.RED, Color.WHITE, Color.YELLOW }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void changeColor(View view) { if (counter == colors.length) { counter = 0; } view.setBackgroundColor(colors[counter++]); } }
根據提示信息 This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints(譯:這個視圖不受約束,它只有設計時位置,因此它會跳轉到(0,0),除非你添加約束)咱們能夠得知這是在提示咱們爲該控件添加約束。
解決措施以下: