基础UI控件:

按钮,编辑框,单选按钮,复选框,计时器,日期选择器,时间选择器,图片按钮,文本框。

Button,EditText,RadioButton,CheckBox,Chronometer,DatePicker,TimePicker,ImageButton,TextView。


图像切换器:ImageSwitcher。


Android基础学习,话不多说,上代码:


activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>        

MainActivity.java:

package com.zzx.showpictures;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.WindowManager;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.ViewSwitcher;public class MainActivity extends AppCompatActivity {    private int[] arrayPicture=new int[]{R.mipmap.img01,R.mipmap.img02,R.mipmap.img03,                                        R.mipmap.img04,R.mipmap.img05,R.mipmap.img06,                                        R.mipmap.img07,R.mipmap.img08,R.mipmap.img09};    private ImageSwitcher imageSwitcher;    private int index;    private float touchDownX;    private float touchUpX;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);    //设置全屏显示        imageSwitcher=findViewById(R.id.imageswitcher);        imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {            @Override            public View makeView() {                ImageView imageView=new ImageView(MainActivity.this);                imageView.setImageResource(arrayPicture[index]);                return imageView;            }        });        imageSwitcher.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                if(event.getAction()==MotionEvent.ACTION_DOWN){                    touchDownX=event.getX();                    return true;                }else if(event.getAction()==MotionEvent.ACTION_UP){                    touchUpX=event.getX();                    if(touchUpX-touchDownX>100){                    //判断为从左向右滑动                        index=index==0?arrayPicture.length-1:index-1;                        //动画资源                        imageSwitcher.setImageResource(arrayPicture[index]);                    }                    else if(touchDownX-touchUpX>100){               //判断为从左向右滑动                        index=index==arrayPicture.length-1?0:index+1;                        //动画资源                        imageSwitcher.setImageResource(arrayPicture[index]);                    }                    return true;                }                return false;            }        });    }}

图片资源随意放上几个即可,建议使用png。

演示效果,因为没有添加动画资源,所以只能看出来切换,并没有看出来切换过程:

我是用alt+左键,在左右两边点击的时候,实现了切换,或者使用从左向右滑动和从右向左滑动也可以实现切换:

更多相关文章

  1. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  2. 一款霸榜 GitHub 的开源 Linux 资源监视器!
  3. android标题栏中添加返回按钮
  4. android 实现男女按钮选择
  5. Android开发者必备的14个工具资源
  6. android 触发Button按钮事件的三种方式
  7. Android(安卓)ANR 分析学习总结(转)
  8. android动画之通过子线程来实现动画
  9. OPhone 2.0的2D动画实践(三)

随机推荐

  1. Android初学心得和一些资料下载
  2. Android(安卓)应用程序主框架搭建
  3. android的一些属性
  4. android google 分屏 多窗口 popup无法显
  5. android studio version 2.3.3 打包签名V
  6. 春招笔记(十七)--安卓第七部分
  7. 高焕堂《android从程序员到架构师之路》
  8. Android(安卓)9.0 init 启动流程
  9. Eclipse项目导入到android studio
  10. 转:Adapter 从源头开始适配!