1. 通讯录功能实现

⚪页面布局代码如下:
activity_main.xml(主界面布局代码)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical">
<!--    打电话--><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="35dp"android:background="#000"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="通讯录"android:textColor="#fff"android:textSize="20sp"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/tvadd"android:layout_alignParentRight="true"android:layout_marginRight="20dp"android:layout_marginTop="6dp"android:text="添加"android:textColor="#fff"android:textSize="18sp"/></RelativeLayout><ListViewandroid:layout_width="wrap_content"android:layout_height="match_parent"android:dividerHeight="2dp"android:id="@+id/lv"/></LinearLayout>

activity_add_layout.xml(添加联系人界面布局代码)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="35dp"android:background="#000"><ImageViewandroid:layout_width="30dp"android:layout_height="25dp"android:layout_marginTop="5dp"android:id="@+id/imgreturn"android:layout_marginLeft="10dp"android:src="@mipmap/row_left"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:layout_toRightOf="@+id/imgreturn"android:text="返回"android:textSize="20sp"android:textColor="#fff"/></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="10dp"android:orientation="vertical"><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/edtName"android:hint="请输入姓名"/><EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/edtTel"android:hint="请输入电话号码"/></LinearLayout><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="120dp"android:layout_margin="10dp"><ImageViewandroid:layout_width="40dp"android:layout_height="120dp"android:src="@mipmap/row_left"android:id="@+id/imgleft"/><ImageViewandroid:layout_width="120dp"android:layout_height="wrap_content"android:layout_centerInParent="true"android:id="@+id/img"android:src="@mipmap/liubei"/><ImageViewandroid:layout_width="40dp"android:layout_height="120dp"android:src="@mipmap/row_right"android:layout_alignParentRight="true"android:id="@+id/imgright"/></RelativeLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_horizontal"><Buttonandroid:layout_width="80dp"android:layout_height="wrap_content"android:id="@+id/btnreset"android:text="重置"android:textSize="20sp"/><Buttonandroid:layout_width="80dp"android:layout_height="wrap_content"android:id="@+id/btnok"android:text="添加"android:textSize="20sp"/></LinearLayout>
</LinearLayout>

item.xml(模板布局代码)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><ImageViewandroid:layout_width="60dp"android:layout_height="80dp"android:id="@+id/lxrimg"android:src="@mipmap/liubei"/><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/lxrname"android:layout_marginLeft="15dp"android:layout_marginTop="10dp"android:text="刘备"android:textSize="20sp"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/lxrtel"android:layout_marginLeft="15dp"android:layout_marginTop="10dp"android:text="12345678"android:textSize="20sp"/></LinearLayout>
</LinearLayout>

⚪Java代码如下:
Main_Activity.java(主界面功能实现代码)

package com.example.ceshi;import androidx.appcompat.app.AppCompatActivity;
import androidx.collection.ArraySet;import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;import java.util.ArrayList;
import java.util.HashMap;public class MainActivity extends AppCompatActivity {private ListView lv;private TextView add;private SimpleAdapter adapter = null;private ArrayList<Person> persons = new ArrayList<Person>();private boolean flag = false;private ArrayList<HashMap<String, Object>> lxrList = new ArrayList<HashMap<String, Object>>();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();Intent intent = this.getIntent();// 从add_layout的intent附加信息中取出添加的联系人信息persons = (ArrayList<Person>) intent.getSerializableExtra("persons");//标记已经通过add_layout界面添加了联系人信息,即persons不为空指针flag = intent.getBooleanExtra("flag", false);if (flag) {for (int i = 0; i < persons.size(); i++) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("imgid", persons.get(i).getImgid());map.put("name", persons.get(i).getName());map.put("tel", persons.get(i).getTel());lxrList.add(map);}String[] from = {"imgid", "name", "tel"};int[] to = {R.id.lxrimg, R.id.lxrname, R.id.lxrtel};adapter = new SimpleAdapter(this, lxrList, R.layout.item, from, to);lv.setAdapter(adapter);}lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {Intent itdail = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+persons.get(position).getTel()) );MainActivity.this.startActivity(itdail);}});// 添加监听事件add.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Intent intent = new Intent(MainActivity.this, add_layout.class);startActivity(intent);}});}void initView() {lv = this.findViewById(R.id.lv);add = this.findViewById(R.id.tvadd);}
}

add_layout.java(添加联系人功能代码)

package com.example.ceshi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;import androidx.appcompat.app.AppCompatActivity;import java.util.ArrayList;public class add_layout extends AppCompatActivity {EditText edtName, edtTel;ImageView imgReturn, imgLeft, imgRight, img;int imgId[] = { R.mipmap.liubei,R.mipmap.caocao,R.mipmap.guanyu, R.mipmap.huangzhong, R.mipmap.lusu};int index = 0;Button btnReset,btnOk;ArrayList<Person> persons=new ArrayList<Person>();private  boolean flag=true;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.setContentView(R.layout.activity_add_layout);initView();//头像图片向一张张右翻imgRight.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (++index >= imgId.length) {index = 0;//翻到最后一张后,再翻到第一张}img.setImageResource(imgId[index]);}});//头像图片向一张张左翻imgLeft.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {if (--index <0) {index = imgId.length-1;//翻到第一张后,再翻到最后一张}img.setImageResource(imgId[index]);}});// 重置按钮监听事件btnReset.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {edtName.setText("");edtTel.setText("");}});// 添加按钮监听事件btnOk.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String name = edtName.getText().toString();String tel = edtTel.getText().toString();int imgid = imgId[index];Person person = new Person(name,tel,imgid);persons.add(person);edtTel.setText("");edtName.setText("");}});// 返回监听事件imgReturn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(add_layout.this, MainActivity.class);intent.putExtra("persons", persons);intent.putExtra("flag", flag);startActivity(intent);}});}void initView() {edtName = (EditText) this.findViewById(R.id.edtName);edtTel = (EditText) this.findViewById(R.id.edtTel);img = (ImageView) this.findViewById(R.id.img);imgLeft = (ImageView) this.findViewById(R.id.imgleft);imgRight = (ImageView) this.findViewById(R.id.imgright);imgReturn= (ImageView) this.findViewById(R.id.imgreturn);btnOk = (Button) this.findViewById(R.id.btnok);btnReset = (Button) this.findViewById(R.id.btnreset);}
}

Person.java
(用于封装联系人所有信息,包含姓名,电话,头像;便于Intent传递ArrayList类型数据,需要Serializable接口)

package com.example.ceshi;import java.io.Serializable;public class Person implements Serializable {private String name;private String tel;private int imgid;public Person(String name, String tel, int imgid) {this.name = name;this.tel = tel;this.imgid = imgid;}public String getName() {return name;}public String getTel() {return tel;}public Object getImgid() {return imgid;}
}

2. 考试系统

布局代码

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/kaoshiXT"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" /><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@android:id/tabcontent"><!--            单选布局--><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/danxuan"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="1.负责管理计算器的硬件资源和如那件资源?"android:textSize="18dp"/><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/single"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/a"android:text="A. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/b"android:text="B. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/c"android:text="C. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/d"android:text="D. 操作系统"/></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/duoxuan1"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="2.负责管理计算器的件资源?"android:textSize="18dp"/><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/single1"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/aa"android:text="A. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/bb"android:text="B. jisuanji系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/cc"android:text="C. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/dd"android:text="D. 操作系统"/></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/tiankong"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="3.负责管ddd理计算器的硬件资源和如那件资源?"android:textSize="18dp"/><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/single2"><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/aaa"android:text="A. 操作系统"/><RadioButtonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/ddd"android:text="D. 操作系统"/></RadioGroup></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/jiandati"android:orientation="vertical"><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="4.负责管理计算器的硬件资源和ddd如那件资源?"android:textSize="18dp"/><RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/single4"></RadioGroup></LinearLayout></FrameLayout></LinearLayout></TabHost>

Java功能代码

package com.example.kaoshixitong;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.widget.TabHost;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TabHost tabHost = (TabHost) findViewById(R.id.kaoshiXT);tabHost.setup();tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("单选题").setContent(R.id.danxuan));tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("多选").setContent(R.id.duoxuan1));tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("填空").setContent(R.id.tiankong));tabHost.addTab(tabHost.newTabSpec("tab01").setIndicator("简答题").setContent(R.id.jiandati));}
}


3. 打地鼠游戏

布局代码

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/table"android:background="@mipmap/caoping"android:shrinkColumns="* "android:stretchColumns="* ">
<!--    第一行--><TableRowandroid:id="@+id/tablerow1"android:layout_height="0dp"android:layout_width="match_parent"android:layout_weight="1"android:gravity="center"><TextViewandroid:id="@+id/tvcount"android:text="击中数:0"android:textSize="20dp"android:gravity="center"android:textColor="#00ffff"android:textStyle="bold"/><ImageViewandroid:id="@+id/im12"android:layout_marginLeft="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im13"android:layout_marginLeft="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im14"android:layout_marginLeft="5dp"android:background="@mipmap/baiban"/><TextViewandroid:id="@+id/tvtime"android:text="倒计时:0:0:00"android:textSize="20dp"android:gravity="center"android:layout_marginLeft="5dp"android:textColor="#00ffff"android:textStyle="bold"/></TableRow><!--    第二行--><TableRowandroid:id="@+id/tablerow2"android:layout_height="0dp"android:layout_width="match_parent"android:layout_weight="1"android:gravity="center"><ImageViewandroid:id="@+id/im21"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im22"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im23"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im24"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im25"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/></TableRow><!--    第三行--><TableRowandroid:id="@+id/tablerow3"android:layout_height="0dp"android:layout_weight="1"android:layout_width="match_parent"android:gravity="center"><ImageViewandroid:id="@+id/im31"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im32"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im33"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im34"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im35"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/></TableRow><!--    第四行--><TableRowandroid:id="@+id/tablerow4"android:layout_height="0dp"android:layout_weight="1"android:layout_width="match_parent"android:gravity="center"><ImageViewandroid:id="@+id/im41"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im42"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im43"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im44"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im45"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/></TableRow><!--    第五行--><TableRowandroid:id="@+id/tablerow5"android:layout_height="0dp"android:layout_weight="1"android:layout_width="match_parent"android:gravity="center"><Buttonandroid:id="@+id/btnraplay"android:text="重玩"android:textSize="25dp"android:background="@android:color/transparent"android:textColor="#00ffff"android:layout_width="108px"android:layout_height="wrap_content"/><ImageViewandroid:id="@+id/im52"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im53"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><ImageViewandroid:id="@+id/im54"android:layout_marginLeft="5dp"android:layout_marginTop="5dp"android:background="@mipmap/baiban"/><Buttonandroid:id="@+id/btnplay"android:text="开始"android:textSize="25dp"android:layout_width="108px"android:background="@android:color/transparent"android:textColor="#00ffff"android:layout_marginLeft="5dp"android:layout_height="wrap_content"/></TableRow>
</TableLayout>

Java功能代码

package com.example.da_di_shu;import androidx.appcompat.app.AppCompatActivity;import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;public class MainActivity extends AppCompatActivity implements View.OnClickListener {private Button btnplay, btnreplay;private TextView tvcount, tvtime;private ImageView[] imgs = new ImageView[21];private int[] imageID = {R.id.im12, R.id.im13, R.id.im14,R.id.im21, R.id.im22, R.id.im23, R.id.im24, R.id.im25,R.id.im31, R.id.im32, R.id.im33, R.id.im34, R.id.im35,R.id.im41, R.id.im42, R.id.im43, R.id.im44, R.id.im45,R.id.im52, R.id.im53, R.id.im54};int count = 0; // 记录击中的老鼠数int time = 60; // 倒计时60秒int oldID = 0, newID = 0;boolean flag = true; // 时间到标志Handler handler = new Handler() {@Overridepublic void handleMessage(Message msg) {imgs[oldID].setBackgroundResource(R.mipmap.baiban);newID =(int) (Math.random()*20);imgs[newID].setBackgroundResource(R.mipmap.ic_launcher);oldID = newID;}};Runnable runnable = new Runnable() {@Overridepublic void run() {while (flag) {//                handler.sendEmptyMessage(0);try {Thread.sleep(1000);Message message = Message.obtain();handler.sendMessage(message);} catch (InterruptedException e) {e.printStackTrace();}}}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();btnplay.setOnClickListener(this);btnreplay.setOnClickListener(this);for (int i = 0; i< imgs.length; i++) {imgs[i].setOnClickListener(this);}}// 定义变量void initView() {tvcount = this.findViewById(R.id.tvcount);tvtime = this.findViewById(R.id.tvtime);btnplay = this.findViewById(R.id.btnplay);btnreplay = this.findViewById(R.id.btnraplay);for (int i = 0; i<imgs.length; i++) {imgs[i] =(ImageView) this.findViewById(imageID[i]);}}//    @Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.btnplay:new MyCount(60*1000, 1000).start();Thread thread1 = new Thread(runnable);thread1.start();break;case R.id.btnraplay:flag = true;new MyCount(60*1000, 1000).start();Thread thread2 = new Thread(runnable);thread2.start();break;default:if (imgs[oldID].getId() == v.getId()) {count++;tvcount.setText("击中数:"+ count);if (count == 20) {Toast.makeText(MainActivity.this, "祝你顺利过关!", Toast.LENGTH_LONG).show();flag = false;}} else {Toast.makeText(MainActivity.this, "对不起,你没有击中!", Toast.LENGTH_SHORT).show();}break;}}@Overridepublic void onPointerCaptureChanged(boolean hasCapture) {super.onPointerCaptureChanged(hasCapture);}// 计时private class MyCount extends CountDownTimer {public MyCount (long time, long interval) {super(time, interval);}@Overridepublic void onFinish() {flag = false;tvtime.setText("时间到!");}@Overridepublic void onTick(long millis) {int hour = (int) millis /1000 / 3600;int minute = (int) millis /1000 % 3600 / 60;int second = (int) millis /1000 % 3600 % 60;tvtime.setText("倒计时:"+hour +":"+minute+":"+second);}}
}


4. 手势实现图片的轮播效果【相册】

通过该实例可以实现【相册APP】

布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ViewFlipperandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/rv"android:flipInterval="2000"><!--    切换时长2s--></ViewFlipper>
</LinearLayout>

功能代码

package com.example.lunbo;import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ViewFlipper;import java.util.ArrayList;public class MainActivity extends Activity implements View.OnTouchListener {private GestureDetector mDetector;private ViewFlipper viewFlipper; // ViewFlipper 手势检测类@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);viewFlipper = findViewById(R.id.rv);ImageView imageView1 = new ImageView(this); // 创建ImageView对象imageView1.setImageResource(R.mipmap.a1); // 设置图片viewFlipper.addView(imageView1); // 将ImageView对象加载到ViewFlipper上ImageView imageView2 = new ImageView(this); // 创建ImageView对象imageView2.setImageResource(R.mipmap.a2); // 设置图片viewFlipper.addView(imageView2); // 将ImageView对象加载到ViewFlipper上ImageView imageView3 = new ImageView(this); // 创建ImageView对象imageView3.setImageResource(R.mipmap.a3); // 设置图片viewFlipper.addView(imageView3); // 将ImageView对象加载到ViewFlipper上ImageView imageView4 = new ImageView(this); // 创建ImageView对象imageView4.setImageResource(R.mipmap.a4); // 设置图片viewFlipper.addView(imageView4); // 将ImageView对象加载到ViewFlipper上viewFlipper.setOnTouchListener((View.OnTouchListener) this);mDetector = new GestureDetector(new simpleGestureListener());}@Overridepublic boolean onTouch(View v, MotionEvent event) {return  mDetector.onTouchEvent(event); // 识别手势}private class simpleGestureListener extends GestureDetector.SimpleOnGestureListener {final int huadong_juli = 100; // 滑动距离final int huadong_sudu = 200; // 滑动速度// 用户按下屏幕就会触发@Overridepublic boolean onDown(MotionEvent e) {return true;}/* 滑屏,用户按下触摸屏,快速移动后松开,有一个 MotionEvent ACTION_DOWN, 多个 ACTION_MOVE, 一个ACTION_UP触发e1: 第一个 ACTION_DOWN MotionEvent         e2: 最后一个 ACTION_MOVE MotionEventvelocityX: X轴上的移动速度         velocityY: Y轴上的移动速度*/// 左右切换@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {// 左滑屏if (e1.getX() -e2.getX() > huadong_juli && Math.abs(velocityX) > huadong_sudu) {viewFlipper.showNext(); // 下一个View} else// 右滑屏if (e2.getX() - e1.getX() > huadong_juli && Math.abs(velocityX) > huadong_sudu) {viewFlipper.showPrevious(); // 上一个View}return true;}// 上下切换@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {// 上滑屏if (e1.getY() -e2.getY() > huadong_juli && Math.abs(velocityY) > huadong_sudu) {viewFlipper.showNext(); // 下一个View} else// 下滑屏if (e2.getY() - e1.getY() > huadong_juli && Math.abs(velocityY) > huadong_sudu) {viewFlipper.showPrevious(); // 上一个View}return true;}}
}

5. APP引导页,图片轮播功能实现

1) ViewPager

【Android】【移动应用开发】APP案列相关推荐

  1. 【Android 进阶】开发APP常见的错误

    科技日益发展,现在创建一款移动App的时间远远的低于以前,这并不稀奇:因为目前超过一半的网络流量都是来源于移动设备.当用户不在电脑旁时,可以通过专用应用程序无缝开始移动体验.令人惋惜的是,许多缺乏经验 ...

  2. java安卓app开发教程_[Android教程] Cordova开发App入门(一)创建android项目

    前言 Apache Cordova是一个开源的移动开发框架.允许使用标准的web技术-HTML5,CSS3和JavaScript做跨平台开发. 应用在每个平台的具体执行被封装了起来,并依靠符合标准的A ...

  3. Android 小米手机开发APP图标更换后还显示原来的图标

    Android修改了APP的图标,发布到应用商店,在小米手机下载APP后发现显示的还是原来的图标,查了资料后发现是 小米开放平台之前设置的完美图标还没修改.因为在小米手机上安装APP后会后台去获取完美 ...

  4. ios按钮点击实现android反馈,iOS开发APP内部实现点击按钮切换语言

    本文主要针对APP国际化进行操作,使APP内部控件显示语言可以不随系统语言做改变,自由切换. 效果如下: Language.gif 核心方法: NSLocalizedStringFromTable(, ...

  5. 工地智能安全帽方案/设计案列/APP

    建筑工地是一个安全事故多发的场所.目前,工程建设规模不断扩大,工艺流程纷繁复杂,如何完善现场施工现场管理,控制事故发生频率,保障文明施工一直是施工企业.政府管理部门关注的焦点.尤其随着社会的不断进步和 ...

  6. java创建医生的对象_基于安卓Android的作物医生App设计开发(MySQL)(含录像)

    基于安卓Android的作物医生App设计开发(MySQL)(含录像)(毕业论文14000字,PHP程序代码,MySQL数据库) 本系统使用软件工程方法进行一系列的分析.设计.实现与测试.使用面向对象 ...

  7. 新建android项目导包,Cordova开发App入门(一)创建android项目

    前言Apache Cordova是一个开源的移动开发框架.允许使用标准的web技术-HTML5,CSS3和JavaScript做跨平台开发. 应用在每个平台的具体执行被封装了起来,并依靠符合标准的AP ...

  8. 0-2岁的app开发人员必读,Android开发APP前的准备事项

    2019独角兽企业重金招聘Python工程师标准>>> 随着移动互联网的兴起,各行各业对移动应用的需求越来越大,从事APP开发的人也越来越多,APP开发行业可以说是方兴未艾.APP开 ...

  9. android app启动图片 加动画效果,Android Studio开发APP启动程序时开屏简单动画效果快速有效解决方案...

    Android Studio开发APP启动程序时开屏简单动画效果快速有效解决方案 大家在设计APP的末期,都会想给APP搞一些"花里胡哨"的特效来提高APP的B格.博主表示亲测有效 ...

  10. 开发一个基于 Android系统车载智能APP

    很久之前就想做一个车载相关的app.需要实现如下功能: (1)每0.2秒更新一次当前车辆的最新速度值. (2)可控制性记录行驶里程. (3)不连接网络情况下获取当前车辆位置.如(北京市X区X路X号) ...

最新文章

  1. 应对AI失控,研究人员提出用“人格障碍治疗”解决问题
  2. 性能优化之使用LongAdder替换AtomicLong
  3. Mybatis常见的面试题总结
  4. leetcode145. 二叉树的后序遍历
  5. 【分布式架构】企业级分布式应用服务EDAS使用攻略(上篇)
  6. excel学习1:合并两个单元格,并把内容用符号隔开。
  7. C:\Users\用户名\AppData\Roaming里面的文件可以删除吗?
  8. 微信公众号开发:Java后台如何处理公众号关注和取关事件
  9. B端市场分析报告(一)
  10. 程序猿杂记——七年之痒
  11. PoseCNN(A Convolutional Neural Network for 6D Object Pose Estimation in Cluttered Scenes)复现记录
  12. BDS/Galileo融合精密单点定位性能评估
  13. varlimo阿米洛机械键盘 win lock锁定
  14. meso-四(4-烷氨基甲酰苯基)卟啉(AFPP);5-(4-氨基苯基)-10,15.20-三苯基卟啉(TPP-NH2);5,10,15,20-四吡啶基苯基卟啉(H2TPyP)齐岳供应
  15. scrapy mysql 豆瓣_Scrapy爬取豆瓣图书保存MySQL实验
  16. 美国「四院院士」为你实力科普深度学习
  17. RapidScada免费开源Scada组态软件系列教程5-系统进阶
  18. pc usb充电测试软件,充电宝都是大骗子?炬为USB测试工具组合,让你马上一清二楚...
  19. DataGrid 中如何加入序列号
  20. 巴菲特致股东的一封信:2010年

热门文章

  1. zen3 服务器芯片,7nm+工艺Zen3两线出击:EPYC服务器先发 锐龙5000紧跟
  2. android恢复微信好友,安卓微信删除好友怎么找回 找回好友详细方法
  3. Windows系统bat批处理常用命令(一)
  4. 软件工程经济学结课报告——兰花智慧大棚监控系统可行性研究报告
  5. 烟雾传感器的matlab程序,单片机烟雾传感器proteus仿真+程序+PCB原理图
  6. 【复习篇】高等代数第五版重难知识点整理(1)
  7. Flash安装低版本方法
  8. 博士生“凡尔赛”大赏:全程靠自己发了篇SCI,导师发奖金拿到手软
  9. AI人工智能仿写在线v.1.2.3
  10. 【原创】ESXI获取虚拟机的moid,并使用VMRC登录远程虚拟机