• Android第4周作业


    activity_main.xml
     
     
    <?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">
     
        <Button
            android:id="@+id/button1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#000000"
            android:layout_centerInParent="true"
            android:text=""
             />
        <Button
            android:id="@+id/button2"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#FF0000"
            android:layout_toLeftOf="@id/button1"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button3"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#0000FF"
            android:layout_toRightOf="@id/button1"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button4"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#00FF00"
            android:layout_above="@id/button1"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button5"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#FFFF00"
            android:layout_toLeftOf="@+id/button4"
            android:layout_above="@id/button2"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button6"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#00FFFF"
            android:layout_toRightOf="@+id/button4"
            android:layout_above="@id/button3"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button7"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#FF0FFF"
            android:layout_below="@id/button1"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button8"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#0FFFFF"
            android:layout_below="@id/button2"
            android:layout_toLeftOf="@id/button7"
            android:layout_centerInParent="true"
            android:text=""
            />
        <Button
            android:id="@+id/button9"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="#FFFF00"
            android:layout_toRightOf="@+id/button4"
            android:layout_below="@id/button3"
            android:layout_centerInParent="true"
            android:text=""
            />
     
     
    </RelativeLayout>
    
    
    
    
    
    
    
    
    
    
    
    
    activity_main.xml
     
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#3424"
        >
        <ImageView
            android:id="@+id/img1"
            android:src="@mipmap/tx"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="60dp"
            android:layout_centerHorizontal="true"
            ></ImageView>
        <TextView
            android:id="@+id/tv1"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginTop="60dp"
            android:layout_below="@id/img1"
            android:layout_toLeftOf="@id/et1"
            android:text="用户名:"
            android:textSize="20dp"
            ></TextView>
        <EditText
            android:id="@+id/et1"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_marginTop="60dp"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/img1"
            android:background="@android:drawable/edit_text"
            ></EditText>
        <TextView
            android:id="@+id/tv2"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_marginTop="60dp"
            android:layout_below="@id/tv1"
            android:layout_toLeftOf="@id/et1"
            android:text="密码:"
            android:textSize="20dp"
            ></TextView>
        <EditText
            android:id="@+id/et2"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_marginTop="60dp"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/et1"
            android:background="@android:drawable/edit_text"
            ></EditText>
        <Button
            android:id="@+id/button1"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/et2"
            android:text="登录"
            android:textSize="20dp"
            android:layout_marginTop="60dp"
            ></Button>
     
    </RelativeLayout>
    
    
    
    
    
    MainActivity.java
     
     
    package com.example.myapplication;
     
    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);
            Button button=(Button)findViewById(R.id.button1) ;
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(MainActivity.this,"按钮被点击",Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    

      

  • 相关阅读:
    @SpringBootApplication
    springboot自动装配介绍
    WebServerInitializedEvent &ApplicationRunner
    springboot 潜入式web容器
    Unable to import maven project: See logs for details
    spring boot2 运行环境
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war
    DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing
    idea中maven下载jar包不完整问题
    Python_报错:SyntaxError: EOL while scanning string literal
  • 原文地址:https://www.cnblogs.com/Syz1107/p/13922434.html
Copyright © 2020-2023  润新知