、设置跑马灯功能

  使用滚动字幕显示标题“请选择你喜欢哪种花”

<?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作业的更多相关文章

  1. Android作业分组与选题

    期末大作业 序号 题目 组员分工 完成度 1 基于安卓系统的游戏开发 2 设计一个安卓手机小游戏 3 Android平台应用——音乐播放器设计 4 基于Android技术的个人博客 5 电子阅读器 6 ...

  2. 简单计算器 安卓 Android 作业

    Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...

  3. Android作业list

    作业1. 请在自己的电脑上完成Android的安装与配置,并完成Hello Android项目.上交自己与项目的合照,将照片传至QQ群中. ------------------------------ ...

  4. Android作业 0923

    计算器小应用 package com.example.myhomework2; import androidx.appcompat.app.AppCompatActivity; import andr ...

  5. Android作业0930

    1.使用ListView和Adapter实现购物商城 Android 布局文件 <?xml version="1.0" encoding="utf-8"? ...

  6. Android作业10/07

    1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...

  7. 错误提示”void is an invalid type for the variable“

    今晚做android作业,出现错误提示:void is an invalid type for the variable, invalid:无效的  variable:变量,在网上找了一下后知道是 方 ...

  8. Android——手机内部文件存储(作业)

    作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...

  9. Android——SharedPreferences存储(作业)

    作业:制作一个登录界面,以SP方式存储用户名.用户下次登录时自动显示上次填写的用户名 layout文件: <?xml version="1.0" encoding=" ...

随机推荐

  1. 亚马逊促销活动Promotion②:Money Off(满减折扣)的设置教程

    满减.折扣是放之四海皆有效的促销手段,虽然亚马逊对卖家有诸多限制,但这个促销方式却是允许的,对亚马逊的卖家而言,这对提升商品销量.打造爆款都是极好的.今天小编来讲讲亚马逊的Money Off要怎么设置 ...

  2. JS前端编码规范

    转自<前端编码规范之JavaScript>,网址:http://www.cnblogs.com/hustskyking/p/javascript-spec.html 一个是保持代码的整洁美 ...

  3. JSON.stringify()方法是将一个javascript值(对象或者数组)转换成为一个JSON字符串;JSON.parse()解析JSON字符串,构造由字符串描述的javascript值或对象

    JSON.stringify()方法是将一个javascript值(对象或者数组)转换成为一个JSON字符串:JSON.parse()解析JSON字符串,构造由字符串描述的javascript值或对象

  4. oracle如何创建存储过程和调用

    oracle存储过程的创建语法 create or replace procedure 存储过程名称 ( --定义输入.输出参数-- 参数名1 in 参数类型, 参数名2 in 参数类型, 参数名3 ...

  5. python输入整数

    #!/usr/bin/env python#ecoding=utf-8'''Created on 2017年11月2日 @author: James zhan''' def fun(n): if n= ...

  6. springboot秒杀课程学习整理1-5

    1)交易模型设计 交易模型(用户下单的交易模型)OrderModel id(String 交易单号使用String), userId,itemId,amount(数量),orderAmount(总金额 ...

  7. Rhino学习教程——1.1

    在Rhino的官网下载好Rhino5.0版本后(Rhino官网会提供下载方式,官网是http://www.xuexiniu.com),双击桌面快捷键,就会出现Rhino的界面(我已经自定义过界面了). ...

  8. myBatis简学

    mybatis使用: ①拷贝相关mybits ②编写对象关系映射,一般都是实体类名+Mapper.xml的格式 ③编写mybits配置文件: a)配置环境 b)配置映射文件地址 ④编写对象操作方法: ...

  9. Ubuntu18下sudo apt install xxx出现问题

    当执行sudo apt install rpm时失败(apt-get也失败),输出如下报错信息: E: Could not get lock /var/lib/dpkg/lock - open (11 ...

  10. thinkphp5和thinkphp3.2.3中URL重写出现No input file specified

    查询后解决办法是打开public目录下的.htaccess文件,把:RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 改为:RewriteRule ^(.*)$ i ...