Big task1 - Experiment task1

Writing an App,the root layout is a vertical LinearLayout with 4 horizontal LinearLayouts and 3 TextViews. The App’s name should contain your name message (initials of your name). 
The 1st horizontal LinearLayout, within 1 TextView and 1 EditText, the width space is 1:3, the text in the TextView is right align. The EditText has the text for hint. 
The 2nd horizontal LinearLayout, within 1 Button and 1 TextView. The TextView shows the message of the EditText when users click the button 
The 3rd horizontal LinearLayout, within 3 RadioButtons (equal width). 
The 4th horizontal LinearLayout, within 3 Checkboxes (equal width). 
The 1st TextView below the last horizontal LinearLayout shows the checked RadioButtons. The text color is red. 
The 2nd TextView shows the checked Checkboxes. The text color is blue. 
The 3rd TextView shows your name and student number. The text font size is 14sp.

翻译:

写一个应用程序,根布局是一个垂直线性布局,有4个水平线性布局和3个文本视图。应用程序的名称应该包含您的姓名信息(您姓名的首字母)。 第一个水平线性布局,在1个文本视图和1个编辑文本内,宽度间隔为1:3,文本视图中的文本右对齐。编辑文本包含提示文本。 第二个水平线性布局,在1个按钮和1个文本视图内。当用户点击按钮时,文本视图显示编辑文本的信息 第三个水平线形布局,在3个单选按钮内(等宽)。 第四个水平线形布局,在3个复选框内(等宽)。 最后一个水平线条布局下方的第一个文本视图显示选中的单选按钮。文本颜色为红色。 第二个文本视图显示选中的复选框。文本颜色为蓝色。 第三个文本视图显示您的姓名和学生编号。文本字体大小为14sp。

首先编辑color.xml文件,其中colorPrimaryDark是原有的蓝色,还添加红色 #D24D57

<?xml version="1.0" encoding="utf-8"?>    #6200EE    #3700B3         //蓝色    #03DAC5    #D24D57

之后再来根据要求编辑我们my_main.xml文件

<?xml version="1.0" encoding="utf-8"?>                                    

根据要求编写MainActivity.java函数

package com.example.lrz_exp1;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.EditText;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.TextView;public class MainActivity extends AppCompatActivity {    CheckBox cb1,cb2,cb3;    TextView tv1,tv2;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.my_main);        final EditText et=findViewById(R.id.et);        Button bt=findViewById(R.id.bt1);        final TextView tv5=findViewById(R.id.tv5);        bt.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                String s1=et.getText().toString();                tv5.setText(s1);            }        });        RadioGroup rg=findViewById(R.id.rg1);        tv1=findViewById(R.id.tv1);        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(RadioGroup group, int checkedId) {                RadioButton rb=findViewById(checkedId);                tv1.setText(rb.getText());            }        });        cb1=findViewById(R.id.cb1);        cb2=findViewById(R.id.cb2);        cb3=findViewById(R.id.cb3);        tv2=findViewById(R.id.tv2);        cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });        cb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });        cb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {            @Override            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {                updateCheckBox();            }        });    }    private void updateCheckBox(){        String s2="";        if(cb1.isChecked()){            s2+=cb1.getText()+" ";        }        if(cb2.isChecked()){            s2+=cb2.getText()+" ";        }        if(cb3.isChecked()){            s2+=cb3.getText()+" ";        }        tv2.setText(s2);    }}

学习笔记,水平有限,若有问题欢迎探讨^.^

更多相关文章

  1. Android7.0中文文档(API)-- LinearLayout.LayoutParams
  2. Android:自动完成文本框
  3. Android7.0中文文档(API)-- AdapterView.OnItemLongClickListener
  4. Android7.0中文文档(API)-- AutoCompleteTextView.Validator
  5. Android与IOS异同点对比(1)------ 显示
  6. android坐标系相关知识点
  7. android.view.InflateException: Binary XML file line #7: Erro
  8. view属性大全
  9. Android布局属性

随机推荐

  1. 【JavaScript案例】购物车全选和自动计算
  2. 前端170面试题+答案学习整理
  3. VUE之组件及传参方式
  4. 【爬虫】利用Python爬虫爬取小麦苗itpub
  5. Python3 常见数据类型的转换
  6. Python-if 判断
  7. Python3与Python2的差异
  8. Python - while 循环
  9. Python 函数(一)
  10. Python 函数(一)