第四周作业
1.绘制九宫格
1 <?xml version="1.0" encoding="utf-8"?> 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 10 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 11 android:layout_width="match_parent" android:layout_height="match_parent" 12 android:paddingTop="200dp" android:paddingLeft="20dp"> 13 14 <Button 15 android:layout_width="80dp" 16 android:layout_height="80dp" 17 android:id="@+id/btn1" 18 android:text="111" 19 android:background="#528654"> 20 </Button> 21 22 <Button 23 android:layout_width="80dp" 24 android:layout_height="80dp" 25 android:id="@+id/btn2" 26 android:text="222" 27 android:layout_toRightOf="@id/btn1" 28 android:background="#896899"> 29 </Button> 30 31 <Button 32 android:layout_width="80dp" 33 android:layout_height="80dp" 34 android:id="@+id/btn3" 35 android:text="333" 36 android:layout_toRightOf="@id/btn2" 37 android:background="#212360"> 38 </Button> 39 40 <Button 41 android:layout_width="80dp" 42 android:layout_height="80dp" 43 android:id="@+id/btn4" 44 android:text="444" 45 android:layout_below="@id/btn1" 46 android:background="#FF2589"> 47 </Button> 48 49 <Button 50 android:layout_width="80dp" 51 android:layout_height="80dp" 52 android:id="@+id/btn5" 53 android:text="555" 54 android:layout_below="@id/btn1" 55 android:layout_toRightOf="@id/btn4" 56 android:background="#008854"> 57 </Button> 58 59 <Button 60 android:layout_width="80dp" 61 android:layout_height="80dp" 62 android:id="@+id/btn6" 63 android:text="666" 64 android:layout_below="@id/btn1" 65 android:layout_toRightOf="@id/btn5" 66 android:background="#788877"> 67 </Button> 68 69 <Button 70 android:layout_width="80dp" 71 android:layout_height="80dp" 72 android:id="@+id/btn7" 73 android:text="777" 74 android:layout_below="@id/btn4" 75 android:background="#896888"> 76 </Button> 77 78 <Button 79 android:layout_width="80dp" 80 android:layout_height="80dp" 81 android:id="@+id/btn8" 82 android:text="888" 83 android:layout_below="@id/btn4" 84 android:layout_toRightOf="@id/btn7" 85 android:background="#DD4588"> 86 </Button> 87 88 <Button 89 android:layout_width="80dp" 90 android:layout_height="80dp" 91 android:id="@+id/btn9" 92 android:text="999" 93 android:layout_below="@id/btn4" 94 android:layout_toRightOf="@id/btn8" 95 android:background="#AA2548"> 96 </Button> 97 </RelativeLayout> 98 99 </androidx.constraintlayout.widget.ConstraintLayout>
2.登录界面制作
点登录时,提示:登录按钮被点击
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/photo" android:layout_width="80dp" android:layout_height="80dp" android:layout_centerInParent="true" android:src="@drawable/photo"></ImageView> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/photo" android:maxLength="15" android:layout_marginTop="13dp" android:text="账号:"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/photo" android:layout_toRightOf="@id/textView1" android:hint="请输入您的账号"></EditText> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/textView1" android:maxLength="20" android:layout_marginTop="25dp" android:text="密码:" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/textView1" android:layout_toRightOf="@id/textView2" android:layout_marginTop="10dp" android:hint="请输入您的密码"> </EditText> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:text="登录" android:textColor="#478595" android:layout_below="@id/textView2" android:layout_marginTop="20dp" android:layout_marginLeft="120dp" android:onClick="click"> </Button> </RelativeLayout>
java代码
package com.example.myhomework1; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button mybutton_one; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mybutton_one = (Button) findViewById(R.id.button); } public void click(View view){ mybutton_one.setText("登录按钮被点击"); } }