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.默认显示第一个功能(微信 ...
随机推荐
- 浅谈JVM线程调度机制及主要策略
在之前有说过线程,应该都知道,所谓线程就是进程中的一个子任务,一个进程有多个线程.今天的话主要就是谈一谈JVM线程调度机制.我们结合线程来说,当我们在做多线程的案例时,如一个经典案例,火车站卖票. * ...
- 微信小程序语音(A)发给别人(B),也能播放,是需要先把语音上传到自己的服务器上才可以
小程序语音(A)发给别人(B),也能播放,是需要先把语音上传到自己的服务器上才可以. https://developers.weixin.qq.com/miniprogram/dev/api/medi ...
- 手把手教你如何玩转CLion
声明:配置是基于CLion的2019.1版本 〇.CLion简介 一.安装 \(JetBrains\)官方下载地址:CLion2019.3 百度网盘:CLion2019.1 个人觉得还是2019.1版 ...
- 014.CI4框架CodeIgniter数据库操作之:查询数据库,并让数据以对象的方式返回查询结果
01. 我们在CI4框架中的Model文件夹新建一个User_model.php的文件,使用的是getResultArray,表示并让数据以数组的方式返回查询结果,代码如下: <?php nam ...
- leetcode1305 All Elements in Two Binary Search Trees
""" Given two binary search trees root1 and root2. Return a list containing all the i ...
- 吴裕雄--天生自然java开发常用类库学习笔记:线程操作案例——生产者与消费者
class Info{ // 定义信息类 private String name = "李兴华"; // 定义name属性 private String content = &qu ...
- CF97B Superset超级集合
CF97B Superset 这题主要是构造难想.看看数据范围发现连\(O(n^2)\)都被卡了,然后 考试的名称提醒我 想到了分治. 坐标按横坐标为关键字排序后找中间的点进行分治不是点分治qwq. ...
- MySql索引原理分析
面试 问:数据库中最常见的慢查询优化方式是什么? 同学A:加索引. 问:为什么加索引能优化慢查询?同学A:...不知道同学B:因为索引其实就是一种优化查询的数据结构,比如Mysql中的索引是用B+树实 ...
- 概率图模型之EM算法
一.EM算法概述 EM算法(Expectation Maximization Algorithm,期望极大算法)是一种迭代算法,用于求解含有隐变量的概率模型参数的极大似然估计(MLE)或极大后验概率估 ...
- ActiveMQ持久化机制和JMS可靠消息
1.ActiveMQ持久化机制 1.1 JDBC将数据持久化到数据库 1.2 AMQ生成日志文件 1.3 KahaDB:本次磁盘生成数据文件(默认) 1.4 LevelDB:谷歌K/V数据库 1.5 ...