当前位置:  编程技术>移动开发
本页文章导读:
    ▪Box2D API 汉语言:b2World 类参考        Box2D API 中文:b2World 类参考 详情请参考:【Software Myzone】:http://www.firedragonpzy.com.cn/index.php/archives/2379 ......
    ▪ Gallery自动循环滚动,手动滚动的平滑切换及存在有关问题        Gallery自动循环滚动,手动滚动的平滑切换及存在问题 来自:http://blog.csdn.net/lenghun00/article/details/7635374     @Gallery配合dot使用时,如果放在RelativeLayout中,则手动滑动有反弹现象,其他layout没.........
    ▪ Titanium SDK/Studio 3.0.0 Beta版公布       Titanium SDK/Studio 3.0.0 Beta版发布 Titanium SDK/Studio 3.0.0 Beta版于昨天(11/6/2012)发布,目前还处于Beta版。官方特别提示”This is a beta release, and as such may contain regressions or other issues. Please do not use .........

[1]Box2D API 汉语言:b2World 类参考
    来源: 互联网  发布时间: 2014-02-18
Box2D API 中文:b2World 类参考
详情请参考:【Software Myzone】:http://www.firedragonpzy.com.cn/index.php/archives/2379

    
[2] Gallery自动循环滚动,手动滚动的平滑切换及存在有关问题
    来源: 互联网  发布时间: 2014-02-18
Gallery自动循环滚动,手动滚动的平滑切换及存在问题

来自:http://blog.csdn.net/lenghun00/article/details/7635374

 

 

@Gallery配合dot使用时,如果放在RelativeLayout中,则手动滑动有反弹现象,其他layout没问题,现在还没弄清原因。
首先继承Gallery重写OnFling函数,去除gallery的滚动惯性

[java] view plaincopyprint?
  • public class MyGallery extends Gallery {  
  •   
  •     public MyGallery(Context context, AttributeSet attrs) {  
  •         super(context, attrs);  
  •         // TODO Auto-generated constructor stub   
  •     }  
  •   
  •     private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {  
  •   
  •         return e2.getX() > e1.getX();  
  •   
  •     }  
  •       
  •     @Override  
  •     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,  
  •             float velocityY) {  
  •         int keyCode;  
  •   
  •         if (isScrollingLeft(e1, e2)) {  
  •   
  •             keyCode = KeyEvent.KEYCODE_DPAD_LEFT;  
  •   
  •         } else {  
  •   
  •             keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;  
  •   
  •         }  
  •   
  •         onKeyDown(keyCode, null);  
  •   
  •         return true;  
  •     }  
  •   
  • }  
  • public class MyGallery extends Gallery {
    
    	public MyGallery(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		// TODO Auto-generated constructor stub
    	}
    
    	private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
    
    		return e2.getX() > e1.getX();
    
    	}
    	
    	@Override
    	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
    			float velocityY) {
    		int keyCode;
    
    		if (isScrollingLeft(e1, e2)) {
    
    			keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
    
    		} else {
    
    			keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
    
    		}
    
    		onKeyDown(keyCode, null);
    
    		return true;
    	}
    
    }
    

     

    @注OnFling直接返回false也能实现类似效果,但那样需要滑动很大距离,图片才会切换,用户体验不好

    第二步,构造adapter

    要想平滑的实现循环滚动,可以让getCount返回一个很大的值,这样gallery就认为是有多个item,item之间的切换动画是平滑的

    [html] view plaincopyprint?
  • public class GalleryAdapter extends BaseAdapter {  
  •   
  •     private LayoutInflater mInflater;  
  •     private Context mContext;  
  •     private int width;  
  •     private int count;  
  •     private int[] mImageIds;  
  •   
  •     public GalleryAdapter(Context context, int[] ids) {  
  •         mContext = context;  
  •         mImageIds = ids;  
  •         mInflater = LayoutInflater.from(mContext);  
  •         DisplayMetrics dm = mContext.getApplicationContext().getResources()  
  •                 .getDisplayMetrics();  
  •         width = dm.widthPixels;  
  •         count = mImageIds.length;  
  •     }  
  •   
  •     @Override  
  •     public int getCount() {  
  •         return Integer.MAX_VALUE;//用于循环滚动  
  •     }  
  •   
  •     @Override  
  •     public Object getItem(int position) {  
  •         return position;  
  •     }  
  •   
  •     @Override  
  •     public long getItemId(int position) {  
  •         return position;  
  •     }  
  •   
  •     @Override  
  •     public View getView(int position, View convertView, ViewGroup parent) {  
  •         position = position % count;  
  •         if (convertView == null) {  
  •             convertView = mInflater.inflate(R.layout.gallery_item, null);  
  •         }  
  •         ImageView v = (ImageView) convertView.findViewById(R.id.img);  
  •         v.setLayoutParams(new Gallery.LayoutParams(width, 200));  
  •         v.setScaleType(ImageView.ScaleType.FIT_XY);  
  •         v.setBackgroundResource(mImageIds[position]);  
  •         return v;  
  •     }  
  •   
  • }  
  • public class GalleryAdapter extends BaseAdapter {
    
    	private LayoutInflater mInflater;
    	private Context mContext;
    	private int width;
    	private int count;
    	private int[] mImageIds;
    
    	public GalleryAdapter(Context context, int[] ids) {
    		mContext = context;
    		mImageIds = ids;
    		mInflater = LayoutInflater.from(mContext);
    		DisplayMetrics dm = mContext.getApplicationContext().getResources()
    				.getDisplayMetrics();
    		width = dm.widthPixels;
    		count = mImageIds.length;
    	}
    
    	@Override
    	public int getCount() {
    		return Integer.MAX_VALUE;//用于循环滚动
    	}
    
    	@Override
    	public Object getItem(int position) {
    		return position;
    	}
    
    	@Override
    	public long getItemId(int position) {
    		return position;
    	}
    
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		position = position % count;
    		if (convertView == null) {
    			convertView = mInflater.inflate(R.layout.gallery_item, null);
    		}
    		ImageView v = (ImageView) convertView.findViewById(R.id.img);
    		v.setLayoutParams(new Gallery.LayoutParams(width, 200));
    		v.setScaleType(ImageView.ScaleType.FIT_XY);
    		v.setBackgroundResource(mImageIds[position]);
    		return v;
    	}
    
    }

     

    第三,实现自动滚动

    由于我们还要手动滚动,所以自动滚动用单独一个进程来实现

    [html] view plaincopyprint?
  • private void startAutoScroll() {  
  •         new Thread() {  
  •             @Override  
  •             public void run() {  
  •                 int count = 0;  
  •                 while (mAutoScroll) {  
  •                     count = 0;  
  •                     while (count < 30) {  
  •                         count++;  
  •                         try {  
  •                             Thread.sleep(100);  
  •                         } catch (InterruptedException e) {  
  •                             e.printStackTrace();  
  •                         }  
  •                         if (mOnTouch) {// 用戶手动滑动时,停止自动滚动  
  •                             count = 0;  
  •                         }  
  •                     }  
  •                     mPosition++;  
  •                     Message msg = mHandler.obtainMessage(SCROLL, mPosition, 0);  
  •                     mHandler.sendMessage(msg);  
  •                 }  
  •             }  
  •   
  •         }.start();  
  •     }  
  •   
  •     private Handler mHandler = new Handler() {  
  •   
  •         @Override  
  •         public void handleMessage(Message msg) {  
  •             switch (msg.what) {  
  •             case SCROLL:  
  •                 mGallery.setSelection(msg.arg1);  
  •                 break;  
  •             }  
  •         }  
  •   
  •     };  
  • private void startAutoScroll() {
    		new Thread() {
    			@Override
    			public void run() {
    				int count = 0;
    				while (mAutoScroll) {
    					count = 0;
    					while (count < 30) {
    						count++;
    						try {
    							Thread.sleep(100);
    						} catch (InterruptedException e) {
    							e.printStackTrace();
    						}
    						if (mOnTouch) {// 用戶手动滑动时,停止自动滚动
    							count = 0;
    						}
    					}
    					mPosition++;
    					Message msg = mHandler.obtainMessage(SCROLL, mPosition, 0);
    					mHandler.sendMessage(msg);
    				}
    			}
    
    		}.start();
    	}
    
    	private Handler mHandler = new Handler() {
    
    		@Override
    		public void handleMessage(Message msg) {
    			switch (msg.what) {
    			case SCROLL:
    				mGallery.setSelection(msg.arg1);
    				break;
    			}
    		}
    
    	};

     

    第四实现手动滚动

    手动滚动时,要停止自动滚动,监听gallery的onTouch事件,DOWN时mOnTouch置为true,UP时mOnTouch置为false即可

    [java] view plaincopyprint?
  • mGallery.setOnTouchListener(new OnTouchListener() {  
  •   
  •             @Override  
  •             public boolean onTouch(View v, MotionEvent event) {  
  •                 int action = event.getAction();  
  •                 if (action == MotionEvent.ACTION_DOWN) {  
  •                     mOnTouch = true;  
  •                 } else if (action == MotionEvent.ACTION_UP) {  
  •                     mOnTouch = false;  
  •                 }  
  •                 return false;  
  •             }  
  •   
  •         });  
  • mGallery.setOnTouchListener(new OnTouchListener() {
    
    			@Override
    			public boolean onTouch(View v, MotionEvent event) {
    				int action = event.getAction();
    				if (action == MotionEvent.ACTION_DOWN) {
    					mOnTouch = true;
    				} else if (action == MotionEvent.ACTION_UP) {
    					mOnTouch = false;
    				}
    				return false;
    			}
    
    		});


    到现在我们已经可以自动滚动,手动滚动时自动滚动也会停止。

    我们也许还需要加上dot提示图片滚动的位置

    [java] view plaincopyprint?
  • LinearLayout layout = (LinearLayout) findViewById(R.id.dot);  
  •         if (mDots == null) {  
  •             mDots = new ImageView[ids.length];  
  •             for (int i = 0; i < ids.length; i++) {  
  •                 if (mDots[i] == null)  
  •                     mDots[i] = new ImageView(this);  
  •   
  •                 mDots[i].setBackgroundResource(R.drawable.banner_tab_unselected);  
  •                 layout.addView(mDots[i], new LinearLayout.LayoutParams(mWidth  
  •                         / ids.length + 1, LayoutParams.WRAP_CONTENT));  
  •             }  
  •             mDots[0].setBackgroundResource(R.drawable.banner_tab_selected);  
  •         }  
  • LinearLayout layout = (LinearLayout) findViewById(R.id.dot);
    		if (mDots == null) {
    			mDots = new ImageView[ids.length];
    			for (int i = 0; i < ids.length; i++) {
    				if (mDots[i] == null)
    					mDots[i] = new ImageView(this);
    
    				mDots[i].setBackgroundResource(R.drawable.banner_tab_unselected);
    				layout.addView(mDots[i], new LinearLayout.LayoutParams(mWidth
    						/ ids.length + 1, LayoutParams.WRAP_CONTENT));
    			}
    			mDots[0].setBackgroundResource(R.drawable.banner_tab_selected);
    		}

     

    [java] view plaincopyprint?
  • mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {  
  •   
  •             @Override  
  •             public void onItemSelected(AdapterView<?> arg0, View view,  
  •                     int position, long arg3) {  
  •                 mDotPosition = position % ids.length;  
  •                 mDots[mDotPosition]  
  •                         .setBackgroundResource(R.drawable.banner_tab_selected);  
  •                 if (mDotPosition != mPreDotPosition)  
  •                     mDots[mPreDotPosition]  
  •                             .setBackgroundResource(R.drawable.banner_tab_unselected);  
  •                 mPreDotPosition = mDotPosition;  
  •             }  
  •   
  •             @Override  
  •             public void onNothingSelected(AdapterView<?> arg0) {  
  •                                   
  •             }  
  •               
  •         });  

  •     
    [3] Titanium SDK/Studio 3.0.0 Beta版公布
        来源: 互联网  发布时间: 2014-02-18
    Titanium SDK/Studio 3.0.0 Beta版发布
    Titanium SDK/Studio 3.0.0 Beta版于昨天(11/6/2012)发布,目前还处于Beta版。
    官方特别提示”This is a beta release, and as such may contain regressions or other issues. Please do not use it in production, and keep backups of all important projects and data. We will follow with additional releases in the coming weeks.“

    New Features in Titanium SDK 3.0.0
    (1)On-Device Debugging
    This release adds support for on-device debugging on Android and iOS. For iOS, on-device debugging requires that both device and the computer running Studio are on the same Wi-Fi network. On Android, debugging takes places over a USB connection.
    (2)Alloy Framework
    This release coincides with the release of the Alloy, a model-view-controller (MVC) framework for Titanium. Alloy is installed automatically if you install Titanium Studio 3.0. If you’re using Titanium from the command line, you can install Alloy manually using npm.
    (3)Titanium Command-Line Interface
    This release includes a preview of a new, Node.js-based command-line interface, titanium, intended to replace the Python titanium.py and and builder.py scripts. For this release, some tasks are delegated to the Python scripts, so Python is still required to build projects. If you are installing Titanium Studio, the new CLI is installed automatically. If you are using Titanium from the command line, you can install the new CLI using npm.
    (4)Event Bubbling API Changes
    This release adds several features to allow more control over event bubbling, as well as more transparency over how bubbling works.
    (5)Android Action Bar Support
    This release includes partial support for the Android action bar element. In particular, we support tab groups displayed using action bar-based tabs, optional menu items can be displayed as action items in the action bar, and expanding and collapsing action items are supported. There are some additional features being added here now.
    (6)Accessibility Features
    This release includes support for voice-over accessibility features on iOS and Android. All view elements support a set of new accessibility properties, which can be used to specify the voice-over text associated with a given UI element.

    New Features in Titanium Studio 3.0.0
    One of the major differences with version 3.0 of the Titanium SDK is that a number of projects come as node modules. Studio will look for a Node.js installation on your system. If it does not find it, it will install it, and then prompt you to install the necessary modules via NPM.
    (1)Performance Improvements
    We’ve made substantial improvements in the editing speed of our JS, CSS and HTML editors.
    (2)Alloy Integration
    Create, compile and run alloy projects. Add widgets to existing projects. New integration makes working with alloy projects easy and simple.
    (3)Node.ACS Integration
    Create, test and deploy new Node.js-based cloud services from inside Studio. Simplified workflow makes it easy to test both client and server locally.
    (4)On-Device Debugging
    Together with the new Titanium 3.0.0 SDK, you can now debug on your Android or iOS device (Android via USB, iOS via WiFi).
    (5)Deprecation Warnings
    Is the code you are using deprecated in the current version of the SDK? New warnings will help guide you to what needs refreshing.

    Appcelerator Developer Blog:
    http://developer.appcelerator.com/blog/2012/11/titanium-sdkstudio-3-0-0-beta-now-available.html

    Release Notes:
    http://docs.appcelerator.com/titanium/release-notes/?version=3.0.0.B

    Doc:
    http://docs.appcelerator.com/titanium/3.0/index.html

        
    最新技术文章:
    ▪Android开发之登录验证实例教程
    ▪Android开发之注册登录方法示例
    ▪Android获取手机SIM卡运营商信息的方法
    ▪Android实现将已发送的短信写入短信数据库的...
    ▪Android发送短信功能代码
    ▪Android根据电话号码获得联系人头像实例代码
    ▪Android中GPS定位的用法实例
    ▪Android实现退出时关闭所有Activity的方法
    ▪Android实现文件的分割和组装
    ▪Android录音应用实例教程
    ▪Android双击返回键退出程序的实现方法
    ▪Android实现侦听电池状态显示、电量及充电动...
    ▪Android获取当前已连接的wifi信号强度的方法
    ▪Android实现动态显示或隐藏密码输入框的内容
    ▪根据USER-AGENT判断手机类型并跳转到相应的app...
    ▪Android Touch事件分发过程详解
    ▪Android中实现为TextView添加多个可点击的文本
    ▪Android程序设计之AIDL实例详解
    ▪Android显式启动与隐式启动Activity的区别介绍
    ▪Android按钮单击事件的四种常用写法总结
    ▪Android消息处理机制Looper和Handler详解
    ▪Android实现Back功能代码片段总结
    ▪Android实用的代码片段 常用代码总结
    ▪Android实现弹出键盘的方法
    ▪Android中通过view方式获取当前Activity的屏幕截...
    ▪Android提高之自定义Menu(TabMenu)实现方法
    ▪Android提高之多方向抽屉实现方法
    ▪Android提高之MediaPlayer播放网络音频的实现方法...
    ▪Android提高之MediaPlayer播放网络视频的实现方法...
    ▪Android提高之手游转电视游戏的模拟操控
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3