、设置跑马灯功能

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

<?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. Creed_颓知乎

    题目背景 二轮省选前的一个最后周,Creed_还在颓知乎. 突然,她看到一个有趣的回答. 紧接着,Creed_点开了评论区,又看到了一个有趣的评论. Creed_想了一下,发现自己并不会,于是她又顺着 ...

  2. python -- 返回函数、匿名函数、装饰器

    返回函数 高阶函数的参数可以是函数,那么其返回值也可以是函数. 闭包 对于高阶函数,内部函数可以引用外部函数的参数和局部变量.当调用外部函数返回内部函数时,相关参数和变量都保存在返回的函数(即内部函数 ...

  3. 使用 HttpClient 进行文件上传

    1.使用 AddPart 方法 public static void upload(String authorization,String baseUrl,String filePath,String ...

  4. Java并发编程相关知识整理

    1.什么是进程.线程.多线程?     进程当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.进程间通讯依靠IPC资源,例如管道.套接字     线程是程序中的 ...

  5. 小T牛 绿色版 18.08.0100

    百度网盘 链接:https://pan.baidu.com/s/1g2PIMBR8YAdz5skH5ogFhw 密码:3o4k 小T牛 小T牛 绿色版 18.08.0100 意见反馈:qq(邮箱):6 ...

  6. JS设置、获取和取消Cookie

    // 设置cookie   function setCookie(name, value, seconds, domain) {       seconds = seconds || 0; // se ...

  7. prefixspan是挖掘频繁子序列,子序列不一定是连续的,当心!!!

    序列模式挖掘是从序列数据库中发现频繁子序列作为模式. 子序列与频繁序列 了解了序列数据的概念,我们再来看看上面是子序列.子序列和我们数学上的子集的概念很类似,也就是说,如果某个序列A所有的项集在序列B ...

  8. C++基础学习_01

    C++基础学习_01 基础知识:1.命名空间,2.IO流(输入输入),3.参数缺省,4.函数重载 1.命名空间 作用:对标识符的名称进行本地化,避免命名冲突 定义:namaspace space_na ...

  9. Daily record-December

    December 11. All circles have the same shape. 所有圆的形状都是相同的.2. She first drew a circle on the board. 她 ...

  10. hdu1098

    Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. ...