`
QCheng5453
  • 浏览: 15884 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Android笔记——Day8 *Animation的使用 *实现用户定位

阅读更多

反正每天看看Mars老师视频,完了自己在总结一下,感觉挺好的--#
1、Animation的使用
··首先先给出一个地址,这个里面对Animation的总结真的是非常细致了,作为参考绝对棒
http://www.cnblogs.com/zxl-jay/archive/2011/10/03/2198632.html
··实现一个控件基本的Animation有两种方法:
一种是在xml文件中定义一个动画效果
二是直接在Java代码中实现。
xml中实现动画:
1)在res/anim文件夹下新建一个xml文件,里面定义了动画效果:
具体的各项参数可以见上面的地址。

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:shareInterpolator="true"
    android:fillAfter="true"
    >
    <alpha 
        android:duration="1800"
        android:fromAlpha="1.0"
        android:toAlpha="0.0"/>
    <scale 
        android:duration="1000"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="3.0"
        android:toYScale="3.0"/>
 
</set>

 


2)在Java文件中生成一个Animation对象,并将上面的xml作为参数传进去。</p>
3)调用控件的startAnimation函数执行动画。

Animation anim = AnimationUtils.loadAnimation(TempTestActivity.this,R.anim.testanim);
image.startAnimation(anim);

 
Java中实现

参照上面的地址,因为个人觉得如果将Animation在xml文件中实现会比较方便管理--#
··实现Frame-by-Frame动画
这种动画实际上就是将一系列图片一次显示出来以产生动画效果。
1)定义一个xml文件,里面定义了动画所需要的图片资源及时间

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="false">
    <item android:drawable="@drawable/wait1" android:duration="800"/>
    <item android:drawable="@drawable/wait2" android:duration="800"/>
    <item android:drawable="@drawable/wait3" android:duration="800"/>
    <item android:drawable="@drawable/wait4" android:duration="800"/>
</animation-list>

 

2)在Java中调用对象的setBackgroundResource函数设置控件的动画l文件。
3)用控件的getBackground函数生成一个AnimationDrawable对象,需要向下转型。</p>
4)启动该AnimationDrawable。

image.setBackgroundResource(R.anim.waiting);
AnimationDrawable anim = (AnimationDrawable)image.getBackground();
anim.start();

 

··另外还可以利用AnimationController设置一个LayoutAnimation,这种方法可以给一系列控件实现动画。由于这种方法我还没用过,所以还是参照上面给出的地址吧--#



2、实现用户定位

如果只是想得到用户当前所在地区的经纬度,实现起来还是比较简单的,借助于LocationManager这个类的对象实现。再贴个地址...http://www.cnblogs.com/hbiao68/archive/2012/01/05/2313653.html


1)首先,用getSystemService(Context.LOCATION_SERVICE)这个函数获取一个LoacationManager对象,注意需要向下转型

2)之后调用该对象的getLastKnownLocation()函数就可以得到最后一次定位的位置。

3)可以为LocationManager类对象绑定监听器实现位置移动时所需做的事件。

 

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
				Log.e("fsadfs",lm.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude()+"");
				
				lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
					
					@Override
					public void onStatusChanged(String provider, int status, Bundle extras) {
						
					}
					
					@Override
					public void onProviderEnabled(String provider) {
						
					}
					
					@Override
					public void onProviderDisabled(String provider) {
						
					}
					
					@Override
					public void onLocationChanged(Location location) {
						Log.e("locationAltitude",""+location.getAltitude());
						Log.e("locationLatitude",""+location.getLatitude());
						Log.e("locationLongitude",""+location.getLongitude());
					}
				});

 

 

此外,附上Android中解析JSON格式数据的方法的文章链接http://www.cnblogs.com/hbiao68/archive/2012/01/02/2309793.html

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics