您的位置:首页 > 其它

简易的日记本

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加载数据,以及设置了一些动画,在listView的adapter中的getView()方法中设置了一些颜色的改变,比较多彩了。。。


//设置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




阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: