Android作业
一、设置跑马灯功能
使用滚动字幕显示标题“请选择你喜欢哪种花”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_flower"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.flower.flowerActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_red_dark"
android:layout_gravity="center"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:text="请选择你喜欢哪种花"
android:singleLine="true"
android:ellipsize="marquee"
android:focusableInTouchMode="true"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:textSize="90sp"
android:id="@+id/biaoti" />
2、按钮
<ImageView
android:layout_marginTop="30dp"
android:layout_width="200dp"
android:layout_height="140dp"
android:layout_gravity="center"
android:id="@+id/iv_tupian"/> <RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:id="@+id/hualei"
> <RadioGroup
android:layout_marginTop="40dp"
android:id="@+id/rg_rg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/rbt_mei"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:checked="true"
android:text="梅花"/>
<RadioButton
android:id="@+id/rbt_shinan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="石楠花"/>
<RadioButton
android:id="@+id/rbt_xiangya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="象牙花"/>
</RadioGroup>
<RadioGroup
android:layout_marginTop="40dp"
android:id="@+id/rg_rg2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/rbt_xiuqiu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="绣球花"/>
<RadioButton
android:id="@+id/rbt_yulan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="玉兰花"/>
<RadioButton
android:id="@+id/rbt_mudan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="牡丹花"/>
</RadioGroup>
</RadioGroup> </LinearLayout>
以上是添加按钮
java部分
package com.example.flower; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView; public class flowerActivity extends AppCompatActivity {
private TextView biaoti;
private ImageView iv_tupian;
private RadioGroup rg_rg1;
private RadioGroup hualei;
private RadioButton rbt_mei;
private RadioButton rbt_shinan;
private RadioButton rbt_xiangya;
private RadioGroup rg_rg2;
private RadioButton rbt_xiuqiu;
private RadioButton rbt_yulan;
private RadioButton rbt_mudan; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flower);
biaoti = (TextView) findViewById(R.id.biaoti);
rbt_mei = (RadioButton) findViewById(R.id.rbt_mei);
rbt_shinan = (RadioButton) findViewById(R.id.rbt_shinan);
rbt_xiangya = (RadioButton) findViewById(R.id.rbt_xiangya);
rbt_xiuqiu = (RadioButton) findViewById(R.id.rbt_xiuqiu);
rbt_yulan = (RadioButton) findViewById(R.id.rbt_yulan);
rbt_mudan = (RadioButton) findViewById(R.id.rbt_mudan);
rg_rg1 = (RadioGroup) findViewById(R.id.rg_rg1);
rg_rg2 = (RadioGroup) findViewById(R.id.rg_rg2);
hualei = (RadioGroup) findViewById(R.id.hualei);
iv_tupian=(ImageView)findViewById(R.id.iv_tupian);
建立响应事件
rg_rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if(rbt_mei.isChecked()){
iv_tupian.setImageResource(R.mipmap.mei);
rg_rg2.clearCheck();
}
if(rbt_shinan.isChecked()){
iv_tupian.setImageResource(R.mipmap.shinan);
rg_rg2.clearCheck();
}
if(rbt_xiangya.isChecked()){
iv_tupian.setImageResource(R.mipmap.xiangya);
rg_rg2.clearCheck();
}
}
});
rg_rg2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if(rbt_xiuqiu.isChecked()){
iv_tupian.setImageResource(R.mipmap.xiuqiu);
rg_rg1.clearCheck();
}
if(rbt_yulan.isChecked()){
iv_tupian.setImageResource(R.mipmap.yulan);
rg_rg1.clearCheck();
}
if(rbt_mudan.isChecked()){
iv_tupian.setImageResource(R.mipmap.mudan);
rg_rg1.clearCheck();
}
}
});
}
}
运行结果如下


二
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main_xy"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.myapplication4.MainActivityXY">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:id="@+id/iv_tupian" /> <Button
android:layout_marginTop="300dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="退出"
android:id="@+id/bt_tuichu" /> </RelativeLayout>
以上是xml的内容
java
package com.example.myapplication4; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast; import static com.example.myapplication4.R.id.time; public class MainActivityXY extends AppCompatActivity {
private ImageView iv_tupian;
private Button bt_tuichu; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_xy);
bt_tuichu = (Button) findViewById(R.id.bt_tuichu);
iv_tupian = (ImageView) findViewById(R.id.iv_tupian);
bt_tuichu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (bt_tuichu.isClickable()) {
Toast.makeText(MainActivityXY.this, "再按一次退出按钮",
Toast.LENGTH_LONG).show();
bt_tuichu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (bt_tuichu.isClickable()) {
MainActivityXY.this.finish();
}
}
});
}
}
});
} public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float x = event.getX();
float y = event.getY();
String pos = "x坐标" + x + "y坐标" + y;
Toast.makeText(this, pos, Toast.LENGTH_LONG).show();
iv_tupian.setImageResource(R.mipmap.chu);
iv_tupian.setX(x - 100);
iv_tupian.setY(y - 150);
}
return super.onTouchEvent(event);
} private long exitTime = 0; @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
finish();
System.exit(0);
}
return true;
}
return super.onKeyDown(keyCode, event);
}
}
结束
Android作业的更多相关文章
- Android作业分组与选题
期末大作业 序号 题目 组员分工 完成度 1 基于安卓系统的游戏开发 2 设计一个安卓手机小游戏 3 Android平台应用——音乐播放器设计 4 基于Android技术的个人博客 5 电子阅读器 6 ...
- 简单计算器 安卓 Android 作业
Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...
- Android作业list
作业1. 请在自己的电脑上完成Android的安装与配置,并完成Hello Android项目.上交自己与项目的合照,将照片传至QQ群中. ------------------------------ ...
- Android作业 0923
计算器小应用 package com.example.myhomework2; import androidx.appcompat.app.AppCompatActivity; import andr ...
- Android作业0930
1.使用ListView和Adapter实现购物商城 Android 布局文件 <?xml version="1.0" encoding="utf-8"? ...
- Android作业10/07
1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...
- 错误提示”void is an invalid type for the variable“
今晚做android作业,出现错误提示:void is an invalid type for the variable, invalid:无效的 variable:变量,在网上找了一下后知道是 方 ...
- Android——手机内部文件存储(作业)
作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...
- Android——SharedPreferences存储(作业)
作业:制作一个登录界面,以SP方式存储用户名.用户下次登录时自动显示上次填写的用户名 layout文件: <?xml version="1.0" encoding=" ...
随机推荐
- 蓝鲸DevOps深度解析系列(2):蓝盾流水线初体验
关注嘉为科技,获取运维新知 前面一篇文章<蓝鲸DevOps深度解析系列(1):蓝盾平台总览>,我们总览了蓝鲸DevOps平台的背景.应用场景.特点和能力: 接下来我们继续解析蓝盾平台的 ...
- vue eventBus使用
类似于iframe之间的possMessage方式传参 1.eventBus.js文件 //用于兄弟组件通信 import Vue from 'vue'; export default new Vue ...
- scrapyd的安装和scrapyd-client
1.创建虚拟环境 ,虚拟环境名为sd mkvirtualenv sd #方便管理 2. 安装 scrapyd pip3 install scrapyd 3. 配置 mkdir /etc/scrapy ...
- FreeMarker与Thymeleaf
FreeMarker 是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯 Java 编写,FreeMarker 被设计用来生成 HTML Web 页面,特别是基于 MVC 模式的应用程序,虽然 ...
- django模型系统(二)
django模型系统(二) 常用查询 每一个django模型类,都有一个默认的管理器,objects QuerySet表示数据库中对象的列表.他可以有0到国歌过滤器.过滤器通过给定参数,缩小查询范围( ...
- Oracle单机Rman笔记[6]---记一次oracle脱机异地还原
系统情况介绍 正式环境:windows 2008 r2-32bit/ Oracle: Release 11.2.0.1.0 目标环境:windows 2012 Standard-64bit / Ora ...
- post传递中文时,可以使用urlEncode编码进行转码
http://tool.chinaz.com/tools/urlencode.aspx
- Druid(新版starter)在SpringBoot下的使用以及优点
Druid是Java语言中最好的数据库连接池.Druid能够提供强大的监控和扩展功能.DruidDataSource支持的数据库:理论上说,支持所有有jdbc驱动的数据库.最近发现Druid在spri ...
- 关于C++中Hash的应用
本文只介绍我们在C++中如何使用Hash这种数据结构达到我们编程的目的,有关Hash的概念和实现不做详谈. C++11新增了一类散列容器包括unordered_set, unordered_map, ...
- 前端页面的适配使用rem换算
前端页面的适配使用rem换算 https://www.cnblogs.com/liangxuru/p/6970629.html 注:本文转载之处:https://www.cnblogs.com/ann ...