、设置跑马灯功能

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

<?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. MYSQL mybatis

     mysql 1 每个语句的结束记得加分号; 2where条件里再做if分支 SELECT *FROM `table` WHERE IF( `parentID` is null, `plan_id` ...

  2. 『高性能模型』轻量级网络MobileNet_v2

    论文地址:MobileNetV2: Inverted Residuals and Linear Bottlenecks 前文链接:『高性能模型』深度可分离卷积和MobileNet_v1 一.Mobil ...

  3. angular 引入编辑器以及控制器的学习和理解。。。

    在angular中引入编辑器的时候花了很长时间,然后发现自己以前根本就没好好用过angular,因为项目是接手的学姐的,学姐又是接手的学姐的,到我这里就只是写写页面的事了. 引入编辑器差了好多好多资料 ...

  4. vue-quill-editor富文本编辑器,上传图片自定义为借口上传

    vue-quill-editor富文本编辑器,上传图片自定义为借口上传 博客地址:https://blog.csdn.net/lyj2018gyq/article/details/82585194

  5. FPM一:简单的road map(GAF)

    首先要有个简单的认识: 1.FPM支持的几种UI配置界面接口: Object Instance Floorplan (OIF) Overview Page Floorplan (OVP) Guided ...

  6. 强化学习(六):n-step Bootstrapping

    n-step Bootstrapping n-step 方法将Monte Carlo 与 one-step TD统一起来. n-step 方法作为 eligibility traces 的引入,eli ...

  7. .net core 获取本地ip及request请求端口

    1.获取ip和端口 string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + " ...

  8. 【jQuery、Express.js】AJAX提交Form

    HTML/CSS代码 构建onclick事件 <div class = "row"> <div class = "col-md-10"> ...

  9. 20175212课下作业 MyCP

    20175212课下作业 MyCP 要求 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2 ...

  10. css选择器权重问题

    important infinity 行间样式 1000(256进制) id 100 class/属性/伪类 10 标签/伪元素 1 通配符 0