App基本界面组件案例
今天的收获颇大呀,我发现了一个更高效快速的学习方法,如果真的是因为学习内容太多,无从下手的话,不妨去别人或者自己崇拜的大佬里的博客园里面转一转,你就会有意外的收获,不仅给你学习的压力,还更直观的给介绍了学习的方向和重点,这真的是捷径,我们要学会观看别人的博客园,从里面找到重点,获得收获。像一些零散的知识点里面都罗列的特别的详细,大佬就是大佬,总有我们崇拜的理由。在一位大佬的博客园里我看到了几个有趣的简易的app,感觉很有趣,就学习了一下。下面的内容我就是学习大佬之精华:
并且为了保存和加强对GitHub的学习,并且把一下代码上传到了GitHub上面,命名(playtest_married):

婚姻建议程序:
一:单选框按钮样例(RadioGroup和RadioButton建立单选框按钮)
strings.xml:
<resources>
<string name="app_name">婚姻建议程序app</string>
<string name="sex">性别</string>
<string name="age">年龄</string>
<string name="btn_ok">确定</string>
<string name="result">建议:</string>
<string name="not_hurry">青春还很富裕,先奋斗,结婚还不急!</string>
<string name="find_couple">时候到了,可以尝试找个对象了!</string>
<string name="get_married">你已经事业有成了,该结婚了!</string>
<string name="boy">男生</string>
<string name="gril">女生</string>
<string name="boy_age_1">小于25岁</string>
<string name="boy_age_2">25岁到30岁</string>
<string name="boy_age_3">大于30岁</string>
<string name="gril_age_1">小于25岁</string>
<string name="gril_age_2">25岁到30岁</string>
<string name="gril_age_3">大于30岁</string>
</resources>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity"> <TextView
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sex"
android:textSize="25sp" />
<RadioGroup
android:id="@+id/radgrpsex"
android:checkedButton="@+id/radbtnboy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radbtnboy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/boy"/>
<RadioButton
android:id="@+id/radbtngril"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/gril"/>
</RadioGroup>
<TextView
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="25sp"/> <RadioGroup
android:id="@+id/radgrpage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:checkedButton="@+id/radbtnage1"> <RadioButton
android:id="@+id/radbtnage1"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_1"/>
<RadioButton
android:id="@+id/radbtnage2"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_2"/>
<RadioButton
android:id="@+id/radbtnage3"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boy_age_3"/>
</RadioGroup>
<Button
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#4CAF50"
android:text="@string/btn_ok"/>
<TextView
android:id="@+id/txtresult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"/> </LinearLayout>
MainActivity.java:
package com.example.playtest; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private Button mbtnok;
private TextView mtxtr;
private RadioGroup mradgrpsex,mradgrpage;
private RadioButton mradbtnage1,mradbtnage2,mradbtnage3; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mbtnok=(Button)findViewById(R.id.btn_ok);
mbtnok.setOnClickListener(btnokOnClick);
mtxtr=(TextView)findViewById(R.id.txtresult);
mradgrpage=(RadioGroup)findViewById(R.id.radgrpage);
mradgrpsex=(RadioGroup)findViewById(R.id.radgrpsex);
mradbtnage1=(RadioButton) findViewById(R.id.radbtnage1);
mradbtnage2=(RadioButton) findViewById(R.id.radbtnage2);
mradbtnage3=(RadioButton) findViewById(R.id.radbtnage3); mradgrpsex.setOnCheckedChangeListener(radgrpsexOnClickedChange);
} private View.OnClickListener btnokOnClick=new View.OnClickListener(){
@Override
public void onClick(View v){
String strres=getString(R.string.result); switch(mradgrpage.getCheckedRadioButtonId()){
case R.id.radbtnage1:
strres+=getString(R.string.not_hurry);break;
case R.id.radbtnage2:
strres+=getString(R.string.find_couple);break;
case R.id.radbtnage3:
strres+=getString(R.string.get_married);break;
}
mtxtr.setText(strres);
}
}; private RadioGroup.OnCheckedChangeListener radgrpsexOnClickedChange=new RadioGroup.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(RadioGroup group,int checkedid){
if(checkedid==R.id.radbtnboy){
mradbtnage1.setText(getString(R.string.boy_age_1));
mradbtnage2.setText(getString(R.string.boy_age_2));
mradbtnage3.setText(getString(R.string.boy_age_3));
}
else{
mradbtnage1.setText(getString(R.string.gril_age_1));
mradbtnage2.setText(getString(R.string.gril_age_2));
mradbtnage3.setText(getString(R.string.gril_age_3));
}
}
};
}
运行结果显示:


二:下拉框(Spinner)和数字转轮(NumberPicker)的使用
这个是在上面的婚姻建议程序app的基础上改的,将其换成了下拉框和数字转轮的形式
strings.xml:
<resources>
<string name="app_name">婚姻建议程序app</string>
<string name="sex">性别</string>
<string name="age">年龄</string>
<string name="btn_ok">确定</string>
<string name="result">建议:</string>
<string name="not_hurry">青春还很富裕,先奋斗,结婚还不急!</string>
<string name="find_couple">时候到了,可以尝试找个对象了!</string>
<string name="get_married">你已经事业有成了,该结婚了!</string>
<string name="boy">男生</string>
<string-array name="sex_list">
<item>男生</item>
<item>女生</item>
</string-array>
<string name="sex_select">请选择性别:</string>
<string name="boy_age_1">小于25岁</string>
<string name="boy_age_2">25岁到30岁</string>
<string name="boy_age_3">大于30岁</string>
<string name="gril_age_1">小于25岁</string>
<string name="gril_age_2">25岁到30岁</string>
<string name="gril_age_3">大于30岁</string>
</resources>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity"> <TextView
android:id="@+id/sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sex"
android:textSize="25sp" />
<Spinner
android:id="@+id/spnsex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/sex_list"
android:spinnerMode="dialog"
android:prompt="@string/sex_select"/>
<TextView
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="25sp"/>
<TextView
android:id="@+id/txtage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"/>
<NumberPicker
android:id="@+id/numage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/> <Button
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#4CAF50"
android:text="@string/btn_ok"/>
<TextView
android:id="@+id/txtresult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="25sp"/> </LinearLayout>
MainActivity.java:
package com.example.playtest; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.Spinner;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private NumberPicker numage;
private Spinner spsex;
private Button mbtnok;
private TextView mtxtresult,mtxtage;
private String strsex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mtxtage=(TextView)findViewById(R.id.txtage);
mtxtage.setText("25"); numage=(NumberPicker)findViewById((R.id.numage));
numage.setMinValue(0);
numage.setMaxValue(100);
numage.setValue(25);
numage.setOnValueChangedListener(numChange); mbtnok=(Button)findViewById(R.id.btn_ok);
mbtnok.setOnClickListener(btnonClick); mtxtresult=(TextView)findViewById(R.id.txtresult);
spsex=(Spinner)findViewById(R.id.spnsex);
spsex.setOnItemSelectedListener(spsexOnItemSelected);
} private View.OnClickListener btnonClick=new View.OnClickListener() {
@Override
public void onClick(View v) {
int age=numage.getValue();
String strresult=getString(R.string.result); if(age<25)
strresult+=getString(R.string.not_hurry);
else if(age>30)
strresult+=getString(R.string.get_married);
else
strresult+=getString(R.string.find_couple);
mtxtresult.setText(strresult);
}
}; private AdapterView.OnItemSelectedListener spsexOnItemSelected=new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
strsex=parent.getSelectedItem().toString();
} @Override
public void onNothingSelected(AdapterView<?> parent) { }
}; private NumberPicker.OnValueChangeListener numChange=new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mtxtage.setText(String.valueOf(newVal));
}
};
}
运行结果:


App基本界面组件案例的更多相关文章
- 四种常见的APP分类界面布局设计案例学习
相信各位对于APP设计,已经很熟练啦.如何在熟练的基础上提高我们界面的优美度,或者是进行APP界面的迭代设计. 重构APP设计布局是我们必须要经历的一个过程. 在之前,学习UI设计的时候,经常要接触到 ...
- App 引导界面
App 引导界面 1.前言 最近在学习实现App的引导界面,本篇文章对设计流程及需要注意的地方做一个浅显的总结. 附上项目链接,供和我水平类似的初学者参考——http://files.cnblogs. ...
- ionic入门之色彩、图标、边距和界面组件:列表
目录: 色彩.图标和边距 色彩 图标 内边距 界面组件:列表 列表:.list 成员容器:.item .item: 嵌入文本 .item : 嵌入图标 .item : 嵌入头像 .item : 嵌入缩 ...
- 精华 ionic入门之色彩、图标、边距和界面组件:列表
目录:色彩.图标和边距色彩图标内边距界面组件:列表列表:.list成员容器:.item.item: 嵌入文本.item : 嵌入图标.item : 嵌入头像.item : 嵌入缩略图.item : 嵌 ...
- 前端笔记之Vue(二)组件&案例&props&计算属性
一.Vue组件(.vue文件) 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器 ...
- 循序渐进VUE+Element 前端应用开发(25)--- 各种界面组件的使用(1)
在我们使用Vue+Element开发前端的时候,往往涉及到很多界面组件的使用,其中很多直接采用Element官方的案例即可,有些则是在这个基础上封装更好利用.更少代码的组件:另外有些则是直接采用第三方 ...
- 循序渐进VUE+Element 前端应用开发(26)--- 各种界面组件的使用(2)
在我们使用Vue+Element开发前端的时候,往往涉及到很多界面组件的使用,其中很多直接采用Element官方的案例即可,有些则是在这个基础上封装更好利用.更少代码的组件:另外有些则是直接采用第三方 ...
- Android界面组件的四种启动方式
Android界面组件启动有四种方式 standard,singleTop,singleTask,singleInstance. standard:每次调用都会都会产生新的组件. singletop: ...
- 安卓开发_慕课网_Fragment实现Tab(App主界面)
学习内容来自“慕课网” 这里用Fragment来实现APP主界面 思路: 底部横向排列4个LinearLayout,每个LinearLayout包含一个图片按钮和一个文字 1.默认显示第一个功能(微信 ...
随机推荐
- CentOS7 部署 Jupyter Notebook
socket.error: [Errno 99] Cannot assign requested address 修改这几处: 1.hostname 参考:https://www.cnblogs.co ...
- 017.CI4框架CodeIgniter数据库操作之:Updata更新修改一条数据
01. 在Model中写入数据库操作的代码如下: <?php namespace App\Models\System; use CodeIgniter\Model; class User_mod ...
- 三十二、CI框架之配置域名和设置默认登陆网站
一.打开routes.php文件,将$route['default_controller'] = 'login'; 修改成我们需要的内容. 二.修改config.php中的base_url数据 三.L ...
- 3-安装RabbitMQ
1. 安装erlang 1.1 下载erlang http://www.erlang.org/downloads/20.1 yum -y install make ncurses-devel gcc ...
- python数据分析基础
---恢复内容开始--- Python数据分析基础(1) //2019.07.09python数据分析基础总结1.python数据分析主要使用IDE是Pycharm和Anaconda,最为常用和方便的 ...
- DevOps - 工程师职责
章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...
- ubuntu 中加速pip指令下载插件的速度
在使用pip下载时很多时候下载速度特别慢,时不时就会发生timeout. 这是因为安装源与本机之间网络不畅导致,其实可以自己指定pip的下载来源,就像指定ubuntu更新源那样. 接下来谈谈步骤: 1 ...
- 适配器之SimpleAdapter
前言: 在写适配器时,SimpleAdapter会经常使用到,虽然他比ArrayAdapter复杂,但是也提供了更多的功能 正文: 我们接下来先从SimpleAdapter中较为简单的显示两行文本开始 ...
- 51nod 1423:最大二“货”
1423 最大二"货" 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 白克喜欢找一个序列 ...
- Windows Server 2008 R2 ntoskrnl.exe 引起蓝屏故障,重新启动
前不久在HP ProLiant DL360 G6的服务器上面安装了Windows Server 2008 R2,系统一到晚上凌晨就出现蓝屏.重启现象,并且在 C:\Windows\Minidump 目 ...