自定义到底怎么切换到底视图谷歌地图切换卫星视图a

android中调用高德地图的自定义标记视图 - 推酷
android中调用高德地图的自定义标记视图
1、在api中的MarkerDemoActivity是标记类,先初始化Amap对象init()、setUpMap(),再去定位(定位可以仿高德的api,也可以查查android自带的定位方法)
2、得到经纬度后,在获取需要标记的坐标,在drawMarkers()里添加需要标记的点
&&&&&&&&&&&&aMap.addMarker(new MarkerOptions().position(mList.get(i)).snippet(myFans.get(i).getNickname()).icon(BitmapDescriptorFactory.defaultMarker()));
3、可以设置窗口模式,再点击标记后自动回调getInfoWindow()、getInfoContents(),如果需要自定义显示图像可以在这两个方法里调用render(marker, mWindow);,同时需要在CustomInfoWindowAdapter()里加入需要显示的布局view & &CustomInfoWindowAdapter() {
mWindow = getLayoutInflater().inflate(R.layout.custom_info_window, null);
mContents = getLayoutInflater().inflate(R.layout.custom_info_contents, null);
// mOptions = (RadioGroup)
// findViewById(R.id.custom_info_window_options);
在render方法里处理标记提示信息具体的内容,包括显示人名、点击事件等等。
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致cad视图切换快捷键,如何自定义输入命令“V”回车,然后选择你想要的视口进行切换并置为当前应用就可以了。 ... cad上下左右前后等几个视口如何通过键盘来切换,而不是通过点.../question/.html
cad中怎样切换到三维视图日&-&我们想要在CAD中绘制三维图就需要进入三维空间,下面由学习啦小编告诉大家cad中怎样切换到三维视图,快跟我一起来学习吧。 cad中切换到三维视图...&...&CAD教程&机械设计-快照-学习啦/cad/jixie/1538975.html
日&-&3d室内建模渲染教程,cad机械制图教程,ps图像处理教程,素材下载,最新软件下载,笔记本... 一般三维模型包含多个面,通过切换三维视图,可以从不同.../Article/pmshj/AutoCAD/20...
日&-&cad2016怎么切换经典界面?之前我们介绍过cad其他版本的切换到经典界面的教程,今天我们就来看看CAD2016经典界面的使用方法,基本上变化不大,...www.jb51.net/autocad/437644.html
视图方向的切换在cad的三维绘图过程中,按住shift键的同时,按下鼠标的中键,然后移动鼠... 视图方向,比如前视、俯视还有等轴测等标准的方向。 这时就需要用到cad的切换视图功.../jishushequ/zwcadwenti/885.html
cad2010怎样切换三维视图日&-&cad2010怎样切换三维视图呢?下面学习啦小编告诉大家cad2010怎样切换三维视图,一... 学习啦【新手上路】 编辑:国柱 发布时间: cad201.../cad/rumen/993150.html-快照-学习啦/cad/rumen/993150.html
cad视图切换快捷键-cad视图
11:35:30| 分类: 默认分类 | 标签: |字号大中小... 傻子进游戏后不知道怎么开枪,陪哥布林玩了好久捉迷藏,终于通关后救出赛丽亚MM。N.../jkmbaz81ns5/blog/static/0...
如何在CAD中画圆柱的轴测视图_百度经验发布时间:&&&&画只有矩形的轴测视图似乎挺简单的。但画有圆的轴测视图就要复杂一点了。&...&电脑&电脑软件-百度经验人点赞cad十字光标变红绿斜了怎么变正轴测.../article/09ea3ede02e8efc0aede3930...
CAD里面二维视图切换成三维视图,怎么切换?在二维平面里做假三维,怎么切换?请高手支招! 下载作业帮 扫二维码下载作业帮 拍照搜题,秒出答案,一键查看所有搜题记录 下载作.../question/7ea3ba9a...
12345678910苹果地图自定义大头针 详情视图 - 简书
苹果地图自定义大头针 详情视图
自定一个继承
MKAnnotation
#import &Foundation/Foundation.h&
#import &MapKit/MapKit.h&
@interface CZAnnotation : NSObject&MKAnnotation&
标记经纬度
@property (nonatomic) CLLocationCoordinate2D
@property (nonatomic, copy) NSString *
标记子标题
@property (nonatomic, copy) NSString *
#import "ViewController.h"
//自定一个
#import "CZAnnotation.h"
#import &MapKit/MapKit.h&
@interface ViewController ()&MKMapViewDelegate&
@property (weak, nonatomic) IBOutlet MKMapView *mapV
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 地图类型
self.mapView.mapType = MKMapTypeS
// 用户位置跟踪模式
self.mapView.userTrackingMode = MKUserTrackingModeF
// 设置mapView代理
self.mapView.delegate =
// 在地图上添加一个 "标记模型"
CZAnnotation *anno = [[CZAnnotation alloc] init];
anno.coordinate = CLLocationCoordinate2DMake(39.539, 116.260);
anno.title = @"广州";
anno.subtitle = @"天河xxxxxx";
[self.mapView addAnnotation:anno];
#pragma mark 定位到当前用户位置
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
// 1.当前位置详细描述
userLocation.title = @"广州";
userLocation.subtitle = @"天河";
#warning 自己测试
//当前的位置详细描述,要显示哪个城市,哪个区-(反地理编码)
// 2.设置显示的region
//MKCoordinateSpan span = MKCoordinateSpanMake(0..145513);
MKCoordinateSpan span = MKCoordinateSpanMake(1.00, 1.0);
MKCoordinateRegion region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span);
self.mapView.region =
#pragma mark 在此方法, 动画效果不起作用,其它方法方法可以
//[self.mapView setRegion:region animated:YES];
#pragma 返回当前位置
- (IBAction)backCurrentLocation{
#pragma mark 添加 "标记视图"
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
NSLog(@"%@",views);
//点哪里添哪里
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
//获取点击的位置
CGPoint touchP = [touch locationInView:touch.view];
NSLog(@"%@",NSStringFromCGPoint(touchP));
//把点击的位置转成经纬度
CLLocationCoordinate2D coordinate = [self.mapView convertPoint:touchP toCoordinateFromView:touch.view];
//在地图上添加当前触摸位置 "标记模型"
CZAnnotation *anno = [[CZAnnotation alloc] init];
anno.coordinate =
[self.mapView addAnnotation:anno];
自定义详情 View
#import "ViewController.h"
#import "CZAnnotation.h"
#import &MapKit/MapKit.h&
@interface ViewController ()&MKMapViewDelegate&
@property (weak, nonatomic) IBOutlet MKMapView *mapV
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 地图类型
self.mapView.mapType = MKMapTypeS
// 用户位置跟踪模式
self.mapView.userTrackingMode = MKUserTrackingModeF
// 设置mapView代理
self.mapView.delegate =
添加自定义 ”标记模型“
-(IBAction)addCustomAnno{
// 在地图上添加一个 "标记模型"
CZAnnotation *anno = [[CZAnnotation alloc] init];
anno.coordinate = CLLocationCoordinate2DMake(39.539, 116.260);
anno.title = @"广州";
anno.subtitle = @"天河xxxxxx";
[self.mapView addAnnotation:anno];
#pragma mark 定位到当前用户位置
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
// 1.当前位置详细描述
userLocation.title = @"广州";
userLocation.subtitle = @"天河";
#warning 自己测试
//当前的位置详细描述,要显示哪个城市,哪个区-(反地理编码)
// 2.设置显示的region
//MKCoordinateSpan span = MKCoordinateSpanMake(0..145513);
MKCoordinateSpan span = MKCoordinateSpanMake(1.00, 1.0);
MKCoordinateRegion region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span);
self.mapView.region =
#pragma mark 在此方法, 动画效果不起作用,其它方法方法可以
//[self.mapView setRegion:region animated:YES];
#pragma mark 在地图上显示 "标记视图" 会调用此方法
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id&MKAnnotation&)annotation{
NSLog(@"%@",annotation);
// 自定义的 "标记模型"
if ([annotation isKindOfClass:[CZAnnotation class]]) {
static NSString *annoViewID = @"CZAnnotationView";
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annoViewID];
//MKAnnotationView *pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annoViewID];
MKPinAnnotationColorRed = 0,
MKPinAnnotationColorGreen,
MKPinAnnotationColorPurple*/
设置 "标记视图" 的颜色
pinView.pinColor = MKPinAnnotationColorP
// ”标记视图“ 由天而降
//pinView.animatesDrop = YES;
// "标记视图" 的图片
#warning 设置从天而降(animatesDrop) 自定义图片就无效
pinView.image = [UIImage imageNamed:@"pin_green"];
// 显示 标记视图 - 详情
pinView.canShowCallout = YES;
// callout 往上走,y值设置负数
pinView.calloutOffset = CGPointMake(0, -5);
// 详情视图 左边的View
UIImageView *imgView = [[UIImageView alloc] init];
imgView.image = [UIImage imageNamed:@"gzlib.jpg"];
imgView.bounds = CGRectMake(0, 0, 40, 40);
pinView.leftCalloutAccessoryView = imgV
// 详情视图 右边的View
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
pinView.rightCalloutAccessoryView =
return pinV
// 返回一个空,标记模型 对应 标记视图 由系统决定
#pragma 返回当前位置
- (IBAction)backCurrentLocation{
#pragma mark 添加 "标记视图"
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
NSLog(@"%@",views);&nbsp&#8250&nbsp&nbsp&#8250&nbsp
实现手指滑动切换视图的自定义布局类ScrollLayout
该类的功能是实现随手指滑动切换页面的功能,类似Gallery(但是Gallery限制太多,比如每页布局必须相同)。有的同学可能会想到我们可
以在 onTouchEvent (MotionEvent
event)方法中进行判断,当左右滑动时,执行startActivity(Context
context)方法达到切换页面的效果。但是使用这种方法进行切换是没有过度效果的,只是刷的一下就过去了,而使用这个继承了ViewGroup的布局
就可以达到这个效果了。如下图所示:ScrollLayout类代码public class ScrollLayout extends ViewGroup {&&&&&&&& // private float startX;&&&&&&&& // private float startY;&&&&&&&& public static boolean startTouch =&&&&&&&& // private boolean canMove =&&&&&&&& private static final String TAG = &ScrollLayout&;&&&&&&&& private Scroller mS&&&&&&&& /*&&&&&&&& &* 速度追踪器,主要是为了通过当前滑动速度判断当前滑动是否为fling&&&&&&&& &*/&&&&&&&& private VelocityTracker mVelocityT&&&&&&&& /*&&&&&&&& &* 记录当前屏幕下标,取值范围是:0 到 getChildCount()-1&&&&&&&& &*/&&&&&&&& private static int mCurS&&&&&&&& // private int mDefaultScreen = 1;&&&&&&&& /*&&&&&&&& &* Touch状态值 0:静止 1:滑动&&&&&&&& &*/&&&&&&&& private static final int TOUCH_STATE_REST = 0;&&&&&&&& private static final int TOUCH_STATE_SCROLLING = 1;&&&&&&&& /*&&&&&&&& &* 记录当前touch事件状态--滑动(TOUCH_STATE_SCROLLING)、静止(TOUCH_STATE_REST 默认)&&&&&&&& &*/&&&&&&&& private int mTouchState = TOUCH_STATE_REST;&&&&&&&& private static final int SNAP_VELOCITY = 600;&&&&&&&& /*&&&&&&&& &* 记录touch事件中被认为是滑动事件前的最大可滑动距离&&&&&&&& &*/&&&&&&&& private int mTouchS&&&&&&&& /*&&&&&&&& &* 记录滑动时上次手指所处的位置&&&&&&&& &*/&&&&&&&& private float mLastMotionX;&&&&&&&& private float mLastMotionY;&&&&&&&& private OnScrollToScreenListener onScrollToScreen =&&&&&&&& public ScrollLayout(Context context, AttributeSet attrs) {&&&&&&&&&&&&&&&&&& this(context, attrs, 0);&&&&&&&& }&&&&&&&& public ScrollLayout(Context context, AttributeSet attrs, int defStyle) {&&&&&&&&&&&&&&&&&& super(context, attrs, defStyle);&&&&&&&&&&&&&&&&&& mScroller = new Scroller(context);&&&&&&&&&&&&&&&&&& // mCurScreen = mDefaultS&&&&&&&&&&&&&&&&&& mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();&&&&&&&&&&&&&&&&&& System.out.println(&aaaaaaaaaaaaaaaaaaaaa& + mTouchSlop);&&&&&&&& }&&&&&&&& @Override&&&&&&&& protected void onLayout(boolean changed, int l, int t, int r, int b) {&&&&&&&&&&&&&&&&&& int childLeft = 0;&&&&&&&&&&&&&&&&&& final int childCount = getChildCount();&&&&&&&&&&&&&&&&&& for (int i = 0; i & childC i++) {&&&&&&&&&&&&&&&&&&&&&&&&&&& final View childView = getChildAt(i);&&&&&&&&&&&&&&&&&&&&&&&&&&& if (childView.getVisibility() != View.GONE) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& final int childWidth = childView.getMeasuredWidth();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& childView.layout(childLeft, 0, childLeft + childWidth,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&childView.getMeasuredHeight());&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& childLeft += childW&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& }&&&&&&&& }&&&&&&&&& @Override&&&&&&& protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {&&&&&&&&&&&&&&&&&& Log.e(TAG, &onMeasure&);&&&&&&&&&&&&&&&&&& super.onMeasure(widthMeasureSpec, heightMeasureSpec);&&&&&&&&&&&&&&&&&& final int width = MeasureSpec.getSize(widthMeasureSpec);&&&&&&&&&&&&&&&&&& final int widthMode = MeasureSpec.getMode(widthMeasureSpec);&&&&&&&&&&&&&&&&&& if (widthMode != MeasureSpec.EXACTLY) {&&&&&&&&&&&&&&&&&&&&&&&&&&& throw new IllegalStateException(&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &ScrollLayout only canmCurScreen run at EXACTLY mode!&);&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& final int heightMode = MeasureSpec.getMode(heightMeasureSpec);&&&&&&&&&&&&&&&&&& if (heightMode != MeasureSpec.EXACTLY) {&&&&&&&&&&&&&&&&&&&&&&&&&&& throw new IllegalStateException(&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &ScrollLayout only can run at EXACTLY mode!&);&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& // The children are given the same width and height as the scrollLayout&&&&&&&&&&&&&&&&& final int count = getChildCount();&&&&&&&&&&&&&&&&&& for (int i = 0; i & i++) {&&&&&&&&&&&&&&&&&&&&&&&&&&& getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& // Log.e(TAG, &moving to screen &+mCurScreen);&&&&&&&&&&&&&&&&&& scrollTo(mCurScreen * width, 0);&&&&&&&&&&&&&&&&&& doScrollAction(mCurScreen);&&&&&&&& }&&&&&&&& /**&&&&&&&& &* 方法名称:snapToDestination 方法描述:根据当前位置滑动到相应界面&&&&&&&& &*&&&&&&&& &* @param whichScreen&&&&&&&& &*/&&&&&&&& public void snapToDestination() {&&&&&&&&&&&&&&&&&& final int screenWidth = getWidth();&&&&&&&&&&&&&&&&&&& final int destScreen = (getScrollX() + screenWidth / 2) / screenW&&&&&&&&&&&&&&&&&& snapToScreen(destScreen);&&&&&&&& }&&&&&&&& /**&&&&&&&& &* 方法名称:snapToScreen 方法描述:滑动到到第whichScreen(从0开始)个界面,有过渡效果&&&&&&&& &* @param whichScreen&&&&&&&& &*/&&&&&&&& public void snapToScreen(int whichScreen) {&&&&&&&&&&&&&&&&&& // get the valid layout page&&&&&&&&&&&&&&&&&& whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));&&&&&&&&&&&&&&&&&& if (getScrollX() != (whichScreen * getWidth())) {&&&&&&&&&&&&&&&&&&&&&&&&&&& final int delta = whichScreen * getWidth() - getScrollX();&&&&&&&&&&&&&&&&&&&&&&&&&&& mScroller.startScroll(getScrollX(), 0, delta, 0,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Math.abs(delta) * 2);&&&&&&&&&&&&&&&&&&&&&&&&&& mCurScreen = whichS&&&&&&&&&&&&&&&&&&&&&&&&&&& doScrollAction(mCurScreen);&&&&&&&&&&&&&&&&&&&&&&&&&&& invalidate(); // Redraw the layout&&&&&&&&&&&&&&&&&& }&&&&&&&& }&&&&&&&& /**&&&&&&&& &* 方法名称:setToScreen 方法描述:指定并跳转到第whichScreen(从0开始)个界面&&&&&&&&& &* @param whichScreen&&&&&&&& &*/&&&&&&& public void setToScreen(int whichScreen) {&&&&&&&&&&&&&&&&&& whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));&&&&&&&&&&&&&&&&&& mCurScreen = whichS&&&&&&&&&&&&&&&&&& scrollTo(whichScreen * getWidth(), 0);&&&&&&&&&&&&&&&&&& doScrollAction(whichScreen);&&&&&&&& }&&&&&&&& public int getCurScreen() {&&&&&&&&&&&&&&&&&& return mCurS&&&&&&&& }&&&&&&&& @Override&&&&&&& public void computeScroll() {&&&&&&&&&&&&&&&&&& // TODO Auto-generated method stub&&&&&&&&&&&&&&&&&& if (puteScrollOffset()) {&&&&&&&&&&&&&&&&&&&&&&&&&&& scrollTo(mScroller.getCurrX(), mScroller.getCurrY());&&&&&&&&&&&&&&&&&&&&&&&&&&& postInvalidate();&&&&&&&&&&&&&&&&&& }&&&&&&&& }&&&&&&&& @Override&&&&&&& public boolean onTouchEvent(MotionEvent event) {&&&&&&&&&&&&&&&&&&& if (mVelocityTracker == null) {&&&&&&&&&&&&&&&&&&&&&&&&&&& mVelocityTracker = VelocityTracker.obtain();&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&& mVelocityTracker.addMovement(event);&&&&&&&&&&&&&&&&&& final int action = event.getAction();&&&&&&&&&&&&&&&&&& final float x = event.getX();&&&&&&&&&&&&&&&&&& // final float y = event.getY();&&&&&&&&&&&&&&&&&& switch (action) {&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_DOWN:&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &event down!&);&&&&&&&&&&&&&&&&&&&&&&&&&&& if (!mScroller.isFinished()) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mScroller.abortAnimation();&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&&&&&&&&& mLastMotionX =&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_MOVE:&&&&&&&&&&&&&&&&&&&&&&&&&&&& int deltaX = (int) (mLastMotionX - x);&&&&&&&&&&&&&&&&&&&&&&&&&&& mLastMotionX =&&&&&&&&&&&&&&&&&&&&&&&&&&& scrollBy(deltaX, 0);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_UP:&&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &event : up&);&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &event : up&);&&&&&&&&&&&&&&&&&&&&&&&&&&&& final VelocityTracker velocityTracker = mVelocityT&&&&&&&&&&&&&&&&&&&&&& &&&& puteCurrentVelocity(1000);&&&&&&&&&&&&&&&&&&&&&&&&&&& int velocityX = (int) velocityTracker.getXVelocity();&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &velocityX:& + velocityX);&&&&&&&&&&&&&&&&&&&&&&&&&&& if (velocityX & SNAP_VELOCITY && mCurScreen & 0) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // Fling enough to move left&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &snap left&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& snapToScreen(mCurScreen - 1);&&&&&&&&&&&&&&&&&&&&&&&&&&& } else if (velocityX & -SNAP_VELOCITY&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& && mCurScreen & getChildCount() - 1) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // Fling enough to move right&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Log.e(TAG, &snap right&);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& snapToScreen(mCurScreen + 1);&&&&&&&&&&&&&&&&&&&&&&&&&&& } else {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& snapToDestination();&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&&&&&&&&&& if (mVelocityTracker != null) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mVelocityTracker.recycle();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mVelocityTracker =&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&&&&&&&&&&& mTouchState = TOUCH_STATE_REST;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_CANCEL:&&&&&&&&&&&&&&&&&&&&&&&&&&& mTouchState = TOUCH_STATE_REST;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&& @Override&&&&&&&& public boolean onInterceptTouchEvent(MotionEvent ev) {&&&&&&&&&&&&&&&&&& // TODO Auto-generated method stub&&&&&&&&&&&&&&&&&& Log.e(TAG, &onInterceptTouchEvent-slop:& + mTouchSlop);&&&&&&&&&&&&&&&&&& final int action = ev.getAction();&&&&&&&&&&&&&&&&&& if ((action == MotionEvent.ACTION_MOVE)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& && (mTouchState != TOUCH_STATE_REST)) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& final float x = ev.getX();&&&&&&&&&&&&&&&&&& final float y = ev.getY();&&&&&&&&&&&&&&&&&& switch (action) {&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_DOWN:&&&&&&&&&&&&&&&&&&&&&&&&&&& mLastMotionX =&&&&&&&&&&&&&&&&&&&&&&&&&&& mLastMotionY =&&&&&&&&&&&&&&&&&&&&&&&&&&& mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& : TOUCH_STATE_SCROLLING;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_MOVE:&&&&&&&&&&&&&&&&&&&&&&&&&&& final int xDiff = (int) Math.abs(mLastMotionX - x);&&&&&&&&&&&&&&&&&&&&&&&&&&& if (xDiff & mTouchSlop) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& if (Math.abs(mLastMotionY - y) / Math.abs(mLastMotionX - x) & 1)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& mTouchState = TOUCH_STATE_SCROLLING;&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_CANCEL:&&&&&&&&&&&&&&&&&& case MotionEvent.ACTION_UP:&&&&&&&&&&&&&&&&&&&&&&&&&&& mTouchState = TOUCH_STATE_REST;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&&&&&&&&&&&&&&&& return mTouchState != TOUCH_STATE_REST;&&&&&&&& }&&&&&&&& /**&&&&&&&&& &* 方法名称:doScrollAction 方法描述:当滑动切换界面时执行相应操作&&&&&&&& &* @param index&&&&&&&& &*/&&&&&&&& private void doScrollAction(int whichScreen) {&&&&&&&&&&&&&&&&&& if (onScrollToScreen != null) {&&&&&&&&&&&&&&&&&&&&&&&&&& onScrollToScreen.doAction(whichScreen);&&&&&&&&&&&&&&&&&& }&&&&&&& }&&&&&&&& /**&&&&&&&&& &* 方法名称:setOnScrollToScreen 方法描述:设置内部接口的实现类实例&&&&&&&&& &* @param index&&&&&&&&& &*/&&&&&&&& public void setOnScrollToScreen(&&&&&&&&&&&&&&&&&&&&&&&&&&& OnScrollToScreenListener paramOnScrollToScreen) {&&&&&&&&&&&&&&&&&& onScrollToScreen = paramOnScrollToS&&&&&&&& }&&&&&&&& /**&&&&&&&&& &* 接口名称:OnScrollToScreen 接口描述:当滑动到某个界面时可以调用该接口下的doAction()方法执行某些操作&&&&&&&&& &* @author wader&&&&&&&& &*/&&&&&&&& public abstract interface OnScrollToScreenListener {&&&&&&&&&&&&&&&&&& public void doAction(int whichScreen);&&&&&&&& }&&&&&&&& /**&&&&&&&& &* 指定默认页面位置&&&&&&&& &* @param position&&&&&&&& &*/&&&&&&&& public void setDefaultScreen(int position) {&&&&&&&&&&&&&&&&&& mCurScreen =&&&&&&&& }}布局文件main.xml&?xml version=&1.0&encoding=&utf-8&?&&&diy.ts.wader.widget.ScrollLayout&&& xmlns:android=&/apk/res/android&&&&& android:id=&@+id/ScrollLayoutTest&&&& android:layout_width=&fill_parent&&& &android:layout_height=&fill_parent&&&&&LinearLayout&&& android:background=&#FF0000&&&& android:layout_width=&fill_parent&&&& android:layout_height=&fill_parent&&&/LinearLayout&&&&FrameLayout&&& android:background=&#00FF00&&&& android:layout_width=&fill_parent&&&& android:layout_height=&fill_parent&&&/FrameLayout&&&&&FrameLayout&&& android:background=&#0000FF&&&&& android:layout_width=&fill_parent&&&& android:layout_height=&fill_parent&&&& &/FrameLayout&&&&&/diy.ts.wader.widget.ScrollLayout&&Activity代码MainActivity.javapublic class MainActivity extends Activity {&&& private ScrollLayout viewC&&& private OnScrollToScreenListener scrollL// 滑动切换屏幕显示内容时的事件回调接口&&& @Override&&& public void onCreate(Bundle savedInstanceState) {&&&&&& super.onCreate(savedInstanceState);&&&&&& setContentView(R.layout.main);&&&&&& viewContainer = (ScrollLayout) findViewById(R.id.ScrollLayoutTest);&&&&&& scrollListener = new OnScrollToScreenListener() {&&&&&&&&&& @Override&&&&&&&&&& public void doAction(int whichScreen) {// 在这里执行滑动切换屏幕显示内容时你想做的操作 &&&&&&&&&&&&& Toast.makeText(MainActivity.this,&&&&&&&&&&&&&&&&&&&& &滑动到了第& + whichScreen + &个屏幕&, 300).show();&&&&&&&&&& }&&&&&& };&&&&& viewContainer.setOnScrollToScreen(scrollListener);// 设置滑动时的监听&&&&&& viewContainer.setDefaultScreen(1);// 设置ScrollLayout的默认显示第几个屏幕的内容&&& }}关键点总结该类和LinearLayout、RelativeLayout等布局都是ViewGroup的子类。LinearLayout可以在属性中指定view的排列方式――横向或纵向,而我们自己写的这个类是通过onLayout(boolean changed, int l, int t, int r, int b)方法来自行指定排列方向的。我们这里指定的是横向,大家可以根据需要改为纵向。该类中用到了一些我们不常用的类,如VelocityTracker和Scroller,大家可以参考Android开发文档研究一下,在文章末尾我对VelocityTracker做了下简单介绍。需
要注意的是:我们需在滑动时做一个简单但很重要的判断,即我们需要简单的判断用户的意图――想横向滑动还是想纵向滑动。相信大家都有所体会,就是我们的手
指在屏幕上滑动时不可能是完全水平或完全垂直的,这样会造成屏幕过于灵敏――我们本想上下滑动却触发了左右切换界面的操作。一个很明显的例子就是当滑动界
面中存在ListView。所以这个简单的判断是很重要的,在ScrollLayout中我们是这样做的:case MotionEvent.ACTION_MOVE:&&&&&&&&&&&&&&&&&&&&final int xDiff = (int) Math.abs(mLastMotionX - x);&&&&&&&&&&&&&&&&&&&&if (xDiff & mTouchSlop) {&&&&&&&&&&&&&&&&&&&&&&&&&&&&&if (Math.abs(mLastMotionY - y) / Math.abs(mLastMotionX - x) & 1)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mTouchState = TOUCH_STATE_SCROLLING;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&我们判断滑动方向与水平方向的夹角是否大于45度,小于45度((Math.abs(mLastMotionY - y) / Math.abs(mLastMotionX - x) & 1))则判定用户想要水平滑动,这时我们截获触屏事件不再向下传递(不再传递给child)而是通过onTouchEvent(MotionEvent event)自行处理,在ScrollLayout中就是切换界面的操作。大于45度则判定用户想要垂直滑动,比如滑动界面中的ListView。建议大家研究下Android的事件拦截和处理机制,虽然不难但很重要。这在ScrollLayout类中也发挥了重要作用。android.view.VelocityTracker类简介说明:这个类帮助我们追踪触摸事件(如:滑动)的速率从而实现fling(快速滑动)和其他一些这样的手势。2.&用法:(1)通过VelocityTracker.obtain()方法获取该类的实例。假设该实例为mVelocityTracker。&&&&&(2)&通过addMovement(MotionEvent)方法将你接收到的MotionEvent(事件)添加到mVelocityTracker实例中开始追踪(速度)。&&&&(3)&若要获得当前手势速率,要先调用computeCurrentVelocity(int)方法计算当前速率。然后分别调用getXVelocity()和getYVelocity()便可获得水平和垂直方向上的速率。&注:以上操作通常情况下在onTouchEvent(MotionEvent event)方法中执行,该方法可以提供事件参数。
上一篇: 前几天因为项目的需要,要在一个ListView中放入另一个ListView,也即在一个ListView的每个ListItem中放入另外一个ListView。但刚开始的时候,会发现放入的小ListView会显示不完全,它的高度始终有问题。上网查了下,发现别人也有遇到这样的问题,而大多数人
下一篇: 功能 获取Android设备屏幕宽、高、dpi密度及横竖屏等参数 代码 /*** 系统参数类** @author wader**/public class MySystemParams {private final String TAG = "SystemParams";private static MySystemPpublic int screenW// 屏幕宽度,单

我要回帖

更多关于 谷歌地图切换卫星视图 的文章

 

随机推荐