简易的日记本
2016-01-23 19:53
375 查看
这个应用只完工了大部分吧,急着学其他内容,就不细化了,有些部分也不会,更重要的是设计的结构不好(面向程序了,没有面向对象),就暂时罢工了,
用到了比较多的动画吧。就大概的说一下动画吧。
一个是welcome界面,仿照了心理Fm启动界面,感觉拉近的视觉效果还是不错的,简单的讲就是一个图片的伸缩变化,其它两个就是简单的TextView,当然自己可以偏好存储一下,设置为用户喜欢的 座右铭还是不错的。
/** * 图片的缩放 * * @param drawableId 图片res */ private void addImageView(int drawableId) { ImageView imageView = new ImageView(context); imageView.setBackground(context.getResources().getDrawable(drawableId)); //scaleToX缩放到多少倍,,tools.getDisPlayWidth() / 2为设备的宽度的一半
//(也可以这样获取float x=context.getResources().getDisplayMetrics().widthPixels/2);等等 scaleAnimation = new ScaleAnimation(1.0f, scaleToX, 1.0f, scaleToY, tools.getDisPlayWidth() / 2, tools.getDisPlayHeight() / 2); //设置时间 scaleAnimation.setDuration(animationTime); //设置动画完成后 的状态 scaleAnimation.setFillAfter(fillAfter); //设置差值器 scaleAnimation.setInterpolator(context, interpolatorset); //开始动画 imageView.startAnimation(scaleAnimation); mRelativeLayout.addView(imageView, layoutParams);
//设置listView每个Item的颜色 viewHolder.getConvertView().setBackgroundColor(FirstActivity.colors[index]);
</pre><pre code_snippet_id="1563398" snippet_file_name="blog_20160123_4_4227466" name="code" class="java">listView加载时设置了布局动画,
// 初始化数据 readData(); // 自定义listView的adapter mAdapter = new MyAdapter(context, beans, R.layout.item); list.setAdapter(mAdapter); // 添加布局动画 LayoutAnimationController controller = new LayoutAnimationController(createAnimationWithAlpha_ScaleAnimation()); // controller.setInterpolator(context,<span style="font-family: Arial, Helvetica, sans-serif;">interpolator.accelerate_decelerate);</span> // 控制每项listVIew的出现顺序 controller.setOrder(LayoutAnimationController.ORDER_NORMAL); list.setLayoutAnimation(controller);
/** * 创建一个拥有边缩放,边透明变化的Animation */ private Animation createAnimationWithAlpha_ScaleAnimation() { AnimationSet animationSet = new AnimationSet(false); Animation scaleAnimation = AnimationUtils.loadAnimation(context, R.anim.scale); AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f); alphaAnimation.setDuration(650); animationSet.setInterpolator(context, interpolator.accelerate_decelerate); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(scaleAnimation); return animationSet; }
左下角加了一个自定义的button ,只是封装成了一个面向程序的方法,一个卫星shi的动画效果,主要运用属性动画OBjectAnimator如下:
/** * 计算子菜单的位置 */ private void calculatePos(ArrayList<Integer> resid) { posX = new ArrayList<Float>();// 子菜单的位置X posY = new ArrayList<Float>();// 子菜单的位置Y Log.e("521huaihuai", "resid.size()=" + resid.size()); double perAngle = (Math.PI / (2 * (resid.size() - 2))); Log.e("521huaihuai", "perAngle=" + perAngle); for (int j = 0; j < resid.size() - 1; j++) { float x = (float) (mRadius * Math.cos(j * perAngle)); posX.add(-x); float y = (float) (mRadius * Math.sin(j * perAngle)); posY.add(y); Log.e("521huaihuai", "x=" + x + ",y=" + y); } }</span>
/** * 位移动画Y * * @param i */ private ObjectAnimator transLateAnimatorXY(float start, float end, int duration, int i) { ObjectAnimator animator = ObjectAnimator.ofFloat(list.get(i), "translationY", - tools.dip2px(start), -(tools.dip2px(end)); animator.setDuration(duration); return animator; } /** * 位移动画X * * @param i */ private ObjectAnimator transLateAnimatorX(float start, float end, int duration, int i) { ObjectAnimator animator = ObjectAnimator.ofFloat(list.get(i), "translationX", -(+1) * tools.dip2px(start), -(+1) * tools.dip2px(end)); animator.setDuration(duration); return animator; }
//开始动画</span>
private void startAnimator(ArrayList<Animator> animators, final int i) { AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setInterpolator(AnimationUtils.loadInterpolator(context, interpolator.accelerate_decelerate));
//每个子菜单的时间延迟 set.setStartDelay(i * delayTime);
set.start();
}
点击子菜单的添加按钮后,跳转到书写界面
自定义一个ScrollView中简单的加了一个editText
在onmeasure方法中处理相应的事件
//当用户是编辑模式时:用户滑动时editText取消焦点,隐藏输入法软盘,当用户点击时editText取得焦点,显示输入法。</span>
//当用户是 查看模式时:editText无焦点,当用户双击时,提示用户是否真的要编辑,在一定时间内再次双击可以进入编辑
//模式。否则一段时间后,自动移除上一次的点击次数,避免误点,</span>
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // 隐藏输入法,方便查看 InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); } if (event.getAction() == MotionEvent.ACTION_UP) { long cutTime = System.currentTimeMillis(); if (cutTime - clickTime > TIME) { clickTime = cutTime; } else { once++; if (once==1) { Toast.makeText(context, "再次双击进行文本编辑", Toast.LENGTH_LONG).show(); oldTime=System.currentTimeMillis(); } if (once==2) { //如果两次双击的时间超过9秒,则认为用户误点,移除once次数 if (System.currentTimeMillis()-oldTime>30*TIME) { oldTime=System.currentTimeMillis(); once=1; Toast.makeText(context, "再次双击进行文本编辑", Toast.LENGTH_LONG).show(); }else { seteditTextclearFocus(false); } } } if ((Math.abs(event.getX() - x) < ABS_MOVE) && (Math.abs(event.getY() - y) < ABS_MOVE)) { if (!clearfocus) { // 取得焦点 editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); // 显示输入法 InputMethodManager imm = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSo 1cca8 ftInput(editText, InputMethodManager.SHOW_FORCED); } else { editText.clearFocus(); } } } if (event.getAction() == MotionEvent.ACTION_DOWN) { x = event.getX(); y = event.getY(); Log.i("521huaihuai", "x=" + x); Log.i("521huaihuai", "y=" + y); } return super.onTouchEvent(event); }</span>
其他涉及contentProvider的存储(有点晕),以及一些细节处理。
可以下载参考http://pan.baidu.com/s/1kU3rYV9
相关文章推荐
- js简易日历
- [礼仪大赛策划方案手段]PPT简易的文字编排+网络大量免费的Flash动画+笔记本都具有的扩展桌面双屏支持功能+投影机 就可以打造一场专业的电视台效果时,有何感想?能弃之这些身边的条件而不用吗?
- 让无JAVA运行时环境的电脑运行jar程序的简易方法
- opencv中的开运算,闭运算,形态学梯度,顶帽和黑帽,Canny算子,Sobel算子,Laplace算子,Scharr滤波器 简易理解。
- vml的简易画图板_1
- cocos2d-x游戏实例(28)-简易动作游戏(6)
- Dota2 AI 简易开发教程(二)——英雄出装及其相关功能
- Spring.NET学习笔记3——实现一个简易的IoC框架(练习篇) Level 100
- Git简易命令归纳
- SDRAM驱动篇之简易SDRAM控制器的verilog代码实现
- CentOS配置简易DNS服务器
- java 文件download简易工程
- MyCat之原理简易分析与实战
- Asp.net 基于Cookie简易的权限判断
- Android开发之利用jsoup制作简易的图书馆图书搜索客户端
- 基于 HTML5 Canvas 的简易 2D 3D 编辑器
- 【转载】实体框架之领域驱动实践(三):案例:一个简易的销售系统
- 简易“线程池”在Python网络爬虫中的应用
- c# FTP上传文件实例代码(简易版)
- C#简易实现数字转换为中文的形式