总结:
1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期 ,切横屏时会执行一次,切竖屏时会执行两次
2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期 ,切横、竖屏时只会执行一次
3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期 ,只会执行onConfigurationChanged方法
注:如果你的sdk的api为13及以上,应该改为:
android:configChanges="orientation|screenSize"
- 棣栧厛锛岃鏄庝竴涓嬶紝ListView涓瘡涓€琛屽寘鎷互涓嬩笁椤癸細
- res/layout/main.xml
聽
< ? xml version = "1.0" encoding = "utf-8" ? >
< LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
聽聽聽聽android:layout_width= "fill_parent" android:layout_height= "fill_parent"
聽聽聽聽android:padding= "10dip" android:orientation= "vertical" >
聽聽聽聽< ListView android:id= "@id/android:list" android:layout_width= "fill_parent"
聽聽聽聽聽聽聽聽android:layout_height= "fill_parent" / >
< / LinearLayout>
鍥犱负缁ф壙浜哃istActivity锛屾墍浠istView 鐨刬d璁剧疆涓?span >"@id/android:list"鏄繀椤荤殑
- res/layout/lvitem.xml
娉ㄦ剰锛?/span>
鍦?span >< RelativeLayout>涓?/span>
android:descendantFocusability= "blocksDescendants"
鍜?span >< ImageButton>涓?/span>
android:focusable = "false"
杩欎袱椤圭殑璁剧疆寰堝叧閿紝濡傛灉涓嶈缃紝灏嗗鑷碙istView鐨処temClick浜嬩欢灏嗘棤娉曡Е鍙戯紝璇ヤ簨浠惰ImageButton鐨刢lick浜嬩欢灞忚斀浜嗐€?/span>
< ? xml version = "1.0" encoding = "utf-8" ? >
< RelativeLayout
聽聽xmlns:android= "http://schemas.android.com/apk/res/android"
聽聽android:layout_width= "fill_parent"
聽聽android:layout_height= "wrap_content"
聽聽android:padding= "5dip"
聽聽android:descendantFocusability= "blocksDescendants" >
聽聽
聽聽< ImageView
聽聽聽聽聽聽android:id= "@+id/ItemImage"
聽聽聽聽android:layout_width= "wrap_content"
聽聽聽聽android:layout_height= "wrap_content"
聽聽聽聽android:padding= "5dip"
聽聽/ >
聽聽
聽聽
聽聽< !--
聽聽聽聽聽聽鎶婃寜閽儗鏅缃负閫忔槑: 聽聽聽聽android:background= "#00000000"
聽聽聽聽聽聽鎶婃寜閽儗鏅缃负鍗婇€忔槑: 聽聽聽聽android:background= "#e0000000"
聽聽聽聽聽聽-->
聽聽< ImageButton
聽聽聽聽聽android:id= "@+id/ItemCloseWin"
聽聽聽聽聽
聽聽聽聽聽android:layout_alignParentRight= "true"
聽聽聽聽聽android:layout_alignTop= "@+id/ItemWinName"
聽聽聽聽聽聽android:layout_alignBottom= "@+id/ItemWinName"
聽聽聽聽聽聽android:layout_width= "wrap_content"
聽聽聽聽聽聽android:layout_height= "wrap_content"
聽聽聽聽聽聽
聽聽聽聽聽聽android:background= "#e0000000"
聽聽聽聽聽聽android:gravity= "left|center_vertical"
聽聽聽聽聽聽android:focusable= "false"
聽聽聽聽聽聽android:src= "@android:drawable/ic_menu_close_clear_cancel"
聽聽/ >
聽聽
聽聽< TextView
聽聽聽聽聽聽android:id= "@+id/ItemWinName"
聽聽聽聽聽聽
聽聽聽聽聽聽android:layout_toRightOf= "@+id/ItemImage"
聽聽聽聽聽聽android:layout_toLeftOf= "@+id/ItemCloseWin"
聽聽聽聽聽聽android:layout_alignTop= "@+id/ItemImage"
聽聽聽聽聽聽android:layout_alignBottom= "@+id/ItemImage"
聽聽聽聽聽聽android:layout_width= "wrap_content"
聽聽聽聽聽聽android:layout_height= "wrap_content"
聽聽聽聽聽聽
聽聽聽聽聽聽android:gravity= "left|center_vertical"
聽聽聽聽聽聽android:textSize= "20dip"
聽聽聽聽聽聽android:text= "title"
聽聽/ >
聽聽聽聽
聽聽聽
< / RelativeLayout>
- 鎺ヤ笅鏉ワ紝鎴戜滑鐪嬬湅缁ф壙ListActivity鐨勫疄鐜?/span>
鍦?span >lvWithButtonExt涓紝涓轰簡鑳藉鐞咺mageButton鐨刢lick浜嬩欢锛屾垜缁ф壙浜咮aseAdapter绫伙紝骞堕噸鏂板疄鐜颁簡getView()鎺ュ彛锛屽湪鍏朵腑鍔犲叆浜咮utton鐨刢licklistener锛岃瑙?/span> lvButtonAdapter绫荤殑瀹炵幇銆?/span>
public class lvWithButtonExt extends ListActivity {
聽聽聽聽@Override
聽聽聽聽protected void onCreate( Bundle savedInstanceState) {
聽聽聽聽聽聽聽聽super . onCreate( savedInstanceState) ;
聽聽聽聽聽聽聽聽setContentView( R. layout . main) ;
聽聽聽聽聽聽聽聽// 鍏宠仈Layout涓殑ListView
聽聽聽聽聽聽聽聽ListView vncListView = ( ListView ) findViewById( android. R. id . list ) ;
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽// 鐢熸垚鍔ㄦ€佹暟缁勶紝鍔犲叆鏁版嵁聽
聽聽聽聽聽聽聽聽ArrayList < HashMap < String , Object > > remoteWindowItem = new ArrayList < HashMap < String , Object > > ( ) ;
聽聽聽聽聽聽聽聽for ( int i= 0; i< 10; i+ + )
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽HashMap < String , Object > map = new HashMap < String , Object > ( ) ;
聽聽聽聽聽聽聽聽聽聽聽聽map . put ( "ItemImage" , R. drawable. firefox) ; //鍥惧儚璧勬簮鐨処D聽
聽聽聽聽聽聽聽聽聽聽聽聽map . put ( "ItemWinName" , "Window ID " + i) ;
聽聽聽聽聽聽聽聽聽聽聽聽map . put ( "ItemCloseWin" , android. R. drawable. ic_menu_close_clear_cancel) ;
聽聽聽聽聽聽聽聽聽聽聽聽remoteWindowItem. add ( map ) ;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽// 鐢熸垚閫傞厤鍣ㄧ殑Item鍜屽姩鎬佹暟缁勫搴旂殑鍏冪礌聽
聽聽聽聽聽聽聽聽lvButtonAdapter listItemAdapter = new lvButtonAdapter(
聽聽聽聽聽聽聽聽聽聽聽聽this ,
聽聽聽聽聽聽聽聽聽聽聽聽remoteWindowItem, //鏁版嵁婧惵?/span>
聽聽聽聽聽聽聽聽聽聽聽聽R. layout . lvitem, //ListItem鐨刋ML瀹炵幇
聽聽聽聽聽聽聽聽聽聽聽聽//鍔ㄦ€佹暟缁勪笌ImageItem瀵瑰簲鐨勫瓙椤孤?/span>
聽聽聽聽聽聽聽聽聽聽聽聽new String [ ] { "ItemImage" , "ItemWinName" , "ItemCloseWin" } ,
聽聽聽聽聽聽聽聽聽聽聽聽//ImageItem鐨刋ML鏂囦欢閲岄潰鐨勪竴涓狪mageView,涓や釜TextView ID聽
聽聽聽聽聽聽聽聽聽聽聽聽new int [ ] { R. id . ItemImage, R. id . ItemWinName, R. id . ItemCloseWin}
聽聽聽聽聽聽聽聽) ;
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽vncListView. setAdapter( listItemAdapter) ;
聽聽聽聽}
聽聽聽聽@Override
聽聽聽聽protected void onListItemClick( ListView l, View v, int position , long id ) {
聽聽聽聽聽聽聽聽// TODO Auto-generated method stub
聽聽聽聽聽聽聽聽super . onListItemClick( l, v, position , id ) ;
聽聽聽聽聽聽聽聽l. getItemAtPosition( position ) ;
聽聽聽聽}
}
- 鎺ヤ笅鏉ワ紝鎴戜滑鐪嬬湅lvButtonAdapter 鐨勫疄鐜?/span>
涓轰簡鍝嶅簲鎸夐挳鐨勭偣鍑讳簨浠讹紝棣栧厛瑕佽褰曟寜閽殑浣嶇疆锛岀劧鍚庝负鎸夐挳璁剧疆clicklistener銆?/p>
鍦ㄩ噸鏂板疄鐜扮殑getView()鎺ュ彛涓紝鎴戜娇鐢ㄤ簡lvButtonListener鐩戝惉绫伙紝鍦ㄦ瀯閫犲嚱鏁颁腑锛岃褰曡鍙凤紝浠ヤ究鍦∣nClick鎺ュ彛涓兘鍑嗙‘鐨勫畾浣嶆寜閽墍鍦ㄧ殑浣嶇疆锛岃繘鑰屽鐩稿簲鐨勮杩涜澶勭悊銆?/span>
public class lvButtonAdapter extends BaseAdapter {
聽聽聽聽private class buttonViewHolder {
聽聽聽聽聽聽聽聽ImageView appIcon;
聽聽聽聽聽聽聽聽TextView appName;
聽聽聽聽聽聽聽聽ImageButton buttonClose;
聽聽聽聽}
聽聽聽聽
聽聽聽聽private ArrayList < HashMap < String , Object > > mAppList;
聽聽聽聽private LayoutInflater mInflater;
聽聽聽聽private Context mContext;
聽聽聽聽private String [ ] keyString;
聽聽聽聽private int [ ] valueViewID;
聽聽聽聽private buttonViewHolder holder;
聽聽聽聽
聽聽聽聽public lvButtonAdapter( Context c, ArrayList < HashMap < String , Object > > appList, int resource,
聽聽聽聽聽聽聽聽聽聽聽聽String [ ] from , int [ ] to) {
聽聽聽聽聽聽聽聽mAppList = appList;
聽聽聽聽聽聽聽聽mContext = c;
聽聽聽聽聽聽聽聽mInflater = ( LayoutInflater) mContext. getSystemService( Context . LAYOUT_INFLATER_SERVICE) ;
聽聽聽聽聽聽聽聽keyString = new String [ from . length ] ;
聽聽聽聽聽聽聽聽valueViewID = new int [ to. length ] ;
聽聽聽聽聽聽聽聽System . arraycopy ( from , 0, keyString, 0, from . length ) ;
聽聽聽聽聽聽聽聽System . arraycopy ( to, 0, valueViewID, 0, to. length ) ;
聽聽聽聽}
聽聽聽聽
聽聽聽聽@Override
聽聽聽聽public int getCount ( ) {
聽聽聽聽聽聽聽聽return mAppList. size ( ) ;
聽聽聽聽}
聽聽聽聽@Override
聽聽聽聽public Object getItem ( int position ) {
聽聽聽聽聽聽聽聽return mAppList. get ( position ) ;
聽聽聽聽}
聽聽聽聽@Override
聽聽聽聽public long getItemId( int position ) {
聽聽聽聽聽聽聽聽return position ;
聽聽聽聽}
聽聽聽聽public void removeItem ( int position ) {
聽聽聽聽聽聽聽聽mAppList. remove ( position ) ;
聽聽聽聽聽聽聽聽this . notifyDataSetChanged( ) ;
聽聽聽聽}
聽聽聽聽
聽聽聽聽@Override
聽聽聽聽public View getView ( int position , View convertView, ViewGroup parent ) {
聽聽聽聽聽聽聽聽if ( convertView ! = null ) {
聽聽聽聽聽聽聽聽聽聽聽聽holder = ( buttonViewHolder) convertView. getTag ( ) ;
聽聽聽聽聽聽聽聽} else {
聽聽聽聽聽聽聽聽聽聽聽聽convertView = mInflater. inflate ( R. layout . lvitem, null ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder = new buttonViewHolder( ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. appIcon = ( ImageView ) convertView. findViewById( valueViewID[ 0] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. appName = ( TextView) convertView. findViewById( valueViewID[ 1] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. buttonClose = ( ImageButton) convertView. findViewById( valueViewID[ 2] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽convertView. setTag( holder) ;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽HashMap < String , Object > appInfo = mAppList. get ( position ) ;
聽聽聽聽聽聽聽聽if ( appInfo ! = null ) {
聽聽聽聽聽聽聽聽聽聽聽聽String aname = ( String ) appInfo. get ( keyString[ 1] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽int mid = ( Integer ) appInfo. get ( keyString[ 0] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽int bid = ( Integer ) appInfo. get ( keyString[ 2] ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. appName. setText ( aname) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. appIcon. setImageDrawable( holder. appIcon. getResources ( ) . getDrawable( mid) ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. buttonClose. setImageDrawable( holder. buttonClose. getResources ( ) . getDrawable( bid) ) ;
聽聽聽聽聽聽聽聽聽聽聽聽holder. buttonClose. setOnClickListener( new lvButtonListener( position ) ) ;
聽聽聽聽聽聽聽聽} 聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽return convertView;
聽聽聽聽}
聽聽聽聽class lvButtonListener implements OnClickListener {
聽聽聽聽聽聽聽聽private int position ;
聽聽聽聽聽聽聽聽lvButtonListener( int pos) {
聽聽聽聽聽聽聽聽聽聽聽聽position = pos;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽@Override
聽聽聽聽聽聽聽聽public void onClick( View v) {
聽聽聽聽聽聽聽聽聽聽聽聽int vid= v. getId ( ) ;
聽聽聽聽聽聽聽聽聽聽聽聽if ( vid = = holder. buttonClose. getId ( ) )
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽removeItem ( position ) ;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
聽
////////////////////////////////////////
澶囨敞1锛?/span> 瀵逛簬Android寮€鍙戞潵璇村鐞嗕竴浜涚晫闈㈤渶瑕佸拰Adapter閫傞厤鍣ㄦ墦浜ら亾锛岃櫧鐒禔ndroid鑷甫浜嗕竴浜涙瘮濡侫rrayAdapter浣嗘槸澶у鏁版儏鍐典笅鏃犳硶婊¤冻鎴戜滑闇€瑕侊紝鎵€浠ュ氨瑕佷粠BaseAdapter娲剧敓涓€涓被婊¤冻鎴戜滑鐗规畩鐨勯渶瑕併€?
聽 棣栧厛鎴戜滑鍙兘閲嶅啓getView()锛岄€氳繃LayoutInflater鐨?span >inflate鏂规硶鏄犲皠涓€涓嚜宸卞畾涔夌殑Layout甯冨眬xml鍔犺浇鎴栦粠xxxView涓垱寤恒€傝繖浜涘ぇ瀹跺彲鑳芥粴鐡滅儌鐔熶簡浣嗘槸浠嶇劧寰堝Android 寮€鍙戣€呭浜嶣aseAdapter涓璶otifyDataSetChanged()鏂规硶涓嶆槸寰堢悊瑙o紝notifyDataSetChanged鏂规硶閫氳繃涓€涓閮ㄧ殑鏂规硶鎺у埗濡傛灉閫傞厤鍣ㄧ殑鍐呭鏀瑰彉鏃堕渶瑕佸己鍒惰皟鐢╣etView鏉ュ埛鏂版瘡涓狪tem鐨勫唴瀹广€?/p>
http://blogimg.chinaunix.net/blog/upfile2/101203142001.jpg
- 1 ndroid展示在线图片
- 2 ndroid junit入门(4)Service测试
- 3 ndroid 多点抚摸实现图片缩放
- 4 ndroid 应用代码打开浏览器,打电话,开地图
- 5 ndroid中运用selector动态改变imageView或ImageViewButton的背景
- 1 十分难缠的signal 11 (SIGSEGV)
- 2 Can't create handler inside thread that has not called Looper.prepare() 错误有关问题
- 3 Dex Loader Unable to execute Multiple dex files define解决办法
- 4 解决 Google Play下载施用 "Google Play Store 已停止运行"
- 5 WAP网页获得用户的手机号码
- 6 如何判断Activity是否在运行
- 7 SlidingMenu+ViewPager兑现侧滑菜单效果
- 8 makeKeyAndVisible的功用
- 9 关于Unable to execute dex: Java heap space 解决方法
- 10 RelativeLayout设置居中对齐有关问题
- 1 播发声音文件AVAudioPlayer
- 2 改变银屏显示方式已经加载图片
- 3 2013-十-31 TCP/IP 协议簇
- 4 Java I/零 总体框架图
- 5 拿碗的铠甲勇者
- 6 女友可能出轨 想知道在QQ和别人的聊天记录
- 7 objective C中的字符串(3)
- 8 java.lang.ClassNotFoundException: Didn't find class "Activity" on path: /da
- 9 LG Optimus G Pro 相干
- 10 怎么创建对话框
- 1 视图切换的形式
- 2 BroadcastReceiver要领
- 3 Andriod耗时操作的处置(音乐播放器欢迎界面)
- 4 Tiledmap编辑操作技巧
- 5 深入viewgroup.onintercepttouchevent1点
- 6 用 lipo 下令裁剪出需要的 architecture
- 7 power键跟音量键组合实现截图功能
- 8 实现默认文字统制的textview
- 9 MGTemplateEngine模版发动机
- 10 疑惑为什么报错了
- 上一篇: 反正屏
- 下一篇: Hybrid App的现实运用项目
去年做的一个项目,在native App里内嵌webapp来实现互动,当时发现运行效率还不是特别满意,所以没太在意,今天心血来潮用iPhone5跑了一遍,发现流畅的几乎看不出来各自滚动特效其实都是JS实现的了。
https://itunes.apple.com/cn/app/xu-song-jiu-tian-xing-kong/id429858385?mt=8
有兴趣研究这方面技术的朋友可以从appstore上下载下来玩玩看哦。
兄弟,毕竟公司项目,开源可不成啊,不过有时间的话我会整理一个博文出来吧,等有空。。。