µ±Ç°Î»Ö㺠´úÂëÃÔ >> Android >> Android ѧϰ Ö® һЩӦµ±×¢ÒâµÄ֪ʶµã×ܽᣨ¶þ£©
  Ïêϸ½â¾ö·½°¸

Android ѧϰ Ö® һЩӦµ±×¢ÒâµÄ֪ʶµã×ܽᣨ¶þ£©

Èȶȣº597   ·¢²¼Ê±¼ä£º2016-05-01 18:43:07.0
Android ѧϰ Ö® һЩӦ¸Ã×¢ÒâµÄ֪ʶµã×ܽᣨ¶þ£©

1.ºÎνUIỊ̈߳ºÖ÷Òª¸ºÔð½çÃæµÄÏìÓ¦ÒÔ¼°»æÖƽçÃæÔªËØ¡£

?

ͨ¹ýSWT±à³ÌµÄÒ»¸öСÀý×Ó˵Ã÷һϣº

ÒÔÏ´úÂ룬±à¹ýSWTÓ¦ÓóÌÐòµÄ¶ÁÕß»á·Ç³£ÊìϤ¡£ËüÒ»°ã³öÏÖÔÚmainº¯ÊýµÄ½áβ¡£ÏÂÃæÀ´×Ðϸ·ÖÎöÒ»ÏÂËüµÄÏêϸÇé¿ö¡£

//µ±´°¿ÚδÊÍ·Åʱwhile (!shell.isDisposed()) {    //Èç¹ûdisplay¶ÔÏóʼþ¶ÓÁÐÖÐûÓÐÁ˵ȴýµÄʼþ£¬¾ÍÈøÃÏ߳̽øÈëµÈ´ý״̬    if (!display.readAndDispatch())        display.sleep();}

?

ÉÏÃæµÄ³ÌÐòʵ¼ÊÉϾÍÊÇÎÒÃÇUIÏ̵߳Ĵ¦ÀíÂß¼­£ºµ±³ÌÐòÆô¶¯ºó£¬UIÏ̻߳á¶ÁȡʼþµÈ´ý¶ÓÁУ¬¿´ÓÐûÓÐʼþµÈ´ý´¦Àí¡£Èç¹ûÓУ¬Ëü»á½øÐÐÏàÓ¦´¦Àí£¬Èç¹ûûÓÐËü»á½øÈë˯Ãß״̬¡£Èç¹ûÓÐеÄʼþµ½À´£¬ËüÓֻᱻ»½ÐÑ£¬½øÐд¦Àí¡£UIÏß³ÌËùÐèÒª´¦ÀíµÄʼþ°üÀ¨Óû§µÄÊó±êºÍ¼üÅ̲Ù×÷ʼþ£¬²Ù×÷ϵͳ»ò³ÌÐòÖз¢³öµÄ»æÖÆʼþ¡£Ò»°ãÀ´Ëµ£¬´¦ÀíʼþµÄ¹ý³ÌÒ²¾ÍÊÇÏìÓ¦Óû§²Ù×÷µÄ¹ý³Ì¡£

Ò»¸öºÃµÄ×ÀÃæÓ¦ÓóÌÐòÐèÒª¶ÔÓû§µÄ²Ù×÷×÷³ö×î¿ìµÄÏìÓ¦£¬Ò²¾ÍÊÇ˵ÎÒÃǵÄUIÏ̱߳ØÐ뾡¿ìµÄ´¦Àí¸÷ÖÖʼþ¡£´ÓÎÒÃdzÌÐòµÄ½Ç¶ÈÀ´Ëµ£¬ÔÚUIÏß³ÌÖÐÎÒÃDz»ÄܽøÐдóÁ¿µÄ¼ÆËã»òÕߵȴý£¬·ñÔòÓû§²Ù×÷ʼþµÃ²»µ½¼°Ê±µÄ´¦Àí¡£Í¨³££¬Èç¹ûÓдóÁ¿µÄ¼ÆËã»òÕßÐèÒª³¤Ê±¼äµÈ´ý£¨ÀýÈç½øÐÐÍøÂç²Ù×÷»òÕßÊý¾Ý¿â²Ù×÷£©Ê±£¬ÎÒÃDZØÐ뽫ÕâЩ³¤Ê±¼ä´¦ÀíµÄ³ÌÐòµ¥¶À¿ª±Ù³öÒ»¸öÏß ³ÌÀ´Ö´ÐС£ÕâÑùËäÈ»ºǫ́ÔËÐÐ×ųÌÐò£¬µ«Ò²²»»áÓ°Ïì½çÃæÉϵIJÙ×÷¡£

³ýÖ÷Ïß³ÌÖ®ÍâµÄËùÓÐÏ̶߳¼ÊÇ·ÇUIÏ̡߳£?

?

2. ϵͳÖжÔ×ÖÌåÀàÐ͵Äת»»´¦Àí·½·¨£º

public static float applyDimension(int unit, float value,                                       DisplayMetrics metrics)    {        switch (unit) {        case COMPLEX_UNIT_PX:            return value;        case COMPLEX_UNIT_DIP:            return value * metrics.density;        case COMPLEX_UNIT_SP:            return value * metrics.scaledDensity;        case COMPLEX_UNIT_PT:            return value * metrics.xdpi * (1.0f/72);        case COMPLEX_UNIT_IN:            return value * metrics.xdpi;        case COMPLEX_UNIT_MM:            return value * metrics.xdpi * (1.0f/25.4f);        }        return 0;    }

?

3.´úÂëÉèÖÿؼþµÄÍâ±ß¾à£º

?

ÔÚAndroidµÄ²¼¾ÖÎļþÖУ¬¿ÉÒÔÉèÖÃMargginÊôÐÔÖ¸¶¨Íâ±ß¾à£¬

?

<ImageView android:layout_margin="5dip" android:src="@drawable/image" />

??

µ«ÊǿؼþÔÚ´úÂëÖÐûÓÐsetMargginÖ®ÀàµÄ·½·¨¿ÉÒÔʹÓᣲ»¹ýLinearLayout . LayoutParamsÖÐÓÐsetMarggin·½·¨£¬

ËùÒÔ¿ÉÒÔʵÏÖΪ£º

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);lp.setMargins(left, top, right, bottom);imageView.setLayoutParams(lp);

?

?4.Android Canvas»æͼ¿¹¾â³Ý½â¾ö·½·¨£º

?

ÏÂÃæµÄ·½·¨Ã²ËÆÐв»Í¨£¬¿´ÕâÀï°É£ºhttp://emmet1988.iteye.com/blog/1144439

?

? ¶ÔÓÚAndroidÀ´ËµCanvasÒ»°ã´óÁ¿ÓÃÓÚ×Ô¶¨ÒåViewºÍÓÎÏ·¿ª·¢ÖУ¬¶ÔÓÚͼÐεĻù´¡»æÖÆÀ࣬ÌṩµÄdrawText¡¢drawBitmapÒÔ¼°drawCircle¶¼ÐèÒª¿¹¾â³Ý´¦Àí²ÅÄÜÈÃÈËÂúÒ⣬ÏÂÃæAndroid123½«ËûÃÇ·ÖΪÁ½´óÖÖÇé¿ö¡£

?Ò»¡¢°üº¬Paint²ÎÊýÇé¿öʱ£¬¶ÔÓÚdrawText¡¢drawBitmapÕâÑùµÄ·½·¨£¬Ò»°ã×îºóÒ»¸ö²ÎÊýΪPaint¶ÔÏó£¬Paint¶ÔÏóÒ»°ãÓÃÓÚÉèÖñÊË¢ÑÕÉ«ºÍ´óС£¬Í¬Ê±°üº¬ÁË¿¹¾â³ÝµÄ·½·¨£¬±ÈÈç˵objPaint.setAntiAlias(true);? Õâ¸ö·½·¨Ö´Ðк󼴿ÉÓбȽÏÃ÷ÏԵĸÄÉÆ¡£

?¶þ¡¢²¿·Ö·½·¨Ã»ÓÐPaint²ÎÊý£¬±ÈÈç˵setDrawFilterÕâ¸ö·½·¨£¬ËüµÄ²ÎÊýÖ»ÓÐ PaintFlagsDrawFilter¶ÔÏó£¬ÎÒÃÇ×Ô¼º¹¹ÔìÒ»¸öеĶÔÏ󣬱ÈÈç˵new PaintFlagsDrawFilter(0,Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG)ÕâÑù¾Í¹ýÂËÆ÷¿ÉÒÔÈÃÎı¾ºÍλͼ¾­¹ýÔ²»¬´¦Àí¡£

?

5.Android xliffºÍ×Ö·û´®×ÊÔ´?£º

ºÜ¶àAndroid¿ª·¢Õß¿ÉÄܻᷢÏÖ²¿·Ö×ÊÔ´×Ö·û´®ÔÚ/res/values/string.xmlÖаüº¬ÓÐÀàËÆxliffµÄ½Úµã£¬XliffÊÇXML Localization Interchange File Format µÄËõд£¬ÖÐÎÄÃûΪXML±¾µØ»¯Êý¾Ý½»»»¸ñʽ£¬¶ÔÓÚÔÚAndroidµÄ×ÊÔ´×Ö·û´®ÖУ¬¿ÉÄÜ»áÓÐÀàËÆÏÂÃæµÄ <xliff:g id="cwj">%1$s</xliff:g> ÕâÀidÎÒÃÇ¿ÉÒÔËæ±ã¶¨Ò壬ºóÃæµÄ%1$sÓеãÏñC#ÖеÄ×Ö·û´®¸ñʽ»¯±êÖ¾£¬ÕâÀï1%±íʾÕâÊǵÚÒ»¸ö¿ÉÌæ»»Á¿£¬Èç¹ûÒ»¸öStringÖÐÓжà¸öÐèÒªÌæ»»µÄ±äÁ¿£¬¿ÉÒÔΪ

? <string name="info">¿ª·¢Õß<xliff:g id="name">%1$s</xliff:g> À´×Ô?<xliff:g id="company">%2$s</xliff:g> ¹«Ë¾</string>

? ¶ÔÓÚÉÏÃæµÄ×Ö·û´®£¬ÔÚ¹¤³ÌÖÐÎÒÃÇ¿ÉÒÔʹÓÃString strInfo=getResources().getString(R.string.info,"cwj","android123"); À´Æ´½Ó£¬·µ»ØÒ»¸öеÄ×Ö·û´®strInfoÖС£

?

6. һЩС֪ʶµãÁ´½Ó¼¯ºÏ£º
1 Android´´½¨ºÍɾ³ý×ÀÃæ¿ì½Ý·½Ê½ http://ypf3027.iteye.com/blog/807597
2 androidÅжϿì½Ý·½Ê½ÊÇ·ñÒѾ­´´½¨µÄ·½·¨ http://elvwong.iteye.com/blog/859800
3 ListViewµÄ¸÷ÖÖʹÓ÷½·¨ http://www.vogella.de/articles/AndroidListView/article.html
4 Context.startService()ÓëContext.bindService()Çø±ð http://blog.csdn.net/tiewantn/article/details/6021022
5 Android ÖÐµÄ Service È«Ãæ×ܽá http://blog.csdn.net/chenlaic/article/details/6143235
6 TextWatcher¼à¿ØEditTextÖеÄÊäÈëÄÚÈݲ¢ÏÞÖÆÆäÊäÈë×Ö·û¸öÊý http://www.cnblogs.com/cat-fang/archive/2011/04/12/2013428.html
7 androidºáÊúÆÁÇл»²»ÖØÆôactivity?? http://crazier9527.iteye.com/blog/918618
8 Àí½âActivity http://blog.csdn.net/richway2010/article/details/6572708
9 android°æ±¾×Ô¶¯Éý¼¶´úÂë http://blog.csdn.net/deaboway/article/details/6431943
10 AndroidÓ¦ÓÃÉý¼¶¹¹ÏëºÍÒªµã×ܽá http://blog.csdn.net/richway2010/article/details/6408258
11 android ÓôúÂëÉèÖÃmarginÊôÐÔ£¬textView¼Ó´Ö http://blog.csdn.net/cenlulu/article/details/6336322
7. ³£ÓÃÑÕÉ«
£¨1£©°ë͸Ã÷µ­ºÚÉ«£º#8f00000f
8.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<±à³ÌС¼Æ>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

?

1.ÈÃÒ»¸öͼƬ͸Ã÷£º

Java´úÂë
  1. Bitmap?buffer?=?Bitmap.createBitmap(width,?height,?Bitmap.Config.ARGB_4444);buffer.eraseColor(Color.TRANSPARENT);???

2.Ö±½Ó·¢ËÍÓʼþ£º

Java´úÂë
  1. Intent?intent?=?new?Intent(Intent.ACTION_SENDTO,??Uri?.fromParts("mailto",?"[email protected]",?null));? ??
  2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);? ??
  3. context.startActivity(intent);???

3.³ÌÐò¿ØÖÆÆÁÄ»±äÁÁ£º

Java´úÂë
  1. WindowManager.LayoutParams?lp?=?getWindow().getAttributes();? ??
  2. lp.screenBrightness?=?100?/?100.0f;? ??
  3. getWindow().setAttributes(lp);??

4.¹ýÂËÌض¨Îı¾

Java´úÂë
  1. Filter?filter?=?myAdapter.getFilter();? ??
  2. filter.filter(mySearchText);???

5.scrollView scrollֹͣʼþ

Java´úÂë
  1. setOnScrollListener(new?OnScrollListener(){???? ??
  2. public?void?onScroll(AbsListView?view,?int?firstVisibleItem,?int?visibleItemCount,?int?totalItemCount)?{?????? ??
  3. //?TODO?Auto-generated?method?stub????}???? ??
  4. public?void?onScrollStateChanged(AbsListView?view,?int?scrollState)?{?????? ??
  5. //?TODO?Auto-generated?method?stub?????? ??
  6. if(scrollState?==?0)?Log.i("a",?"scrolling?stopped...");????}??});}???

6. ¶ÔÓÚÌض¨µÄ³ÌÐò ·¢ÆðÒ»¸ö¹ØÁª¹©´ò¿ª

C/C++´úÂë
  1. Bitmap?bmp?=?getImageBitmap(jpg);? ??
  2. String?path?=?getFilesDir().getAbsolutePath()?+?"/test.png";? ??
  3. File?file?=?new?File(path);? ??
  4. FileOutputStream?fos?=?new?FileOutputStream(file);? ??
  5. bmp.compress(?CompressFormat.PNG,?100,?fos?);? ??
  6. ??fos.close();? ??
  7. ?? ??
  8. ???Intent?intent?=?new?Intent();? ??
  9. ???intent.setAction(android?.content.Intent.ACTION_VIEW);? ??
  10. ???intent.setDataAndType(Uri?.fromFile(new?File(path)),?"image/png");? ??
  11. ???startActivity(intent);? ??
  12. ¶ÔÓÚͼƬÉϱߵIJ»ÊÊÓÃË÷Òý¸ñʽ»á³ö´í¡£? ??
  13. Intent?intent?=?new?Intent();?? ??
  14. intent.setAction(android?.content.Intent.ACTION_VIEW);?? ??
  15. File?file?=?new?File("/sdcard/test.mp4");?? ??
  16. intent.setDataAndType(Uri?.fromFile(file),?"video/*");?? ??
  17. startActivity(intent);? ??
  18. ??
  19. Intent?intent?=?new?Intent();?? ??
  20. intent.setAction(android?.content.Intent.ACTION_VIEW);?? ??
  21. File?file?=?new?File("/sdcard/test.mp3");?? ??
  22. intent.setDataAndType(Uri?.fromFile(file),?"audio/*");?? ??
  23. startActivity(intent);???

7.ÉèÖÃÎı¾Íâ¹Û

Java´úÂë
  1. setTextAppearance(context,?android?.R.style.TextAppearance_Medium);? ??
  2. android?:textAppearance="?android?:attr/textAppearanceMedium"??

8.ÉèÖõ¥¶ÀµÄ·¢Æðģʽ£º

Java´úÂë
  1. <activity???????? ??
  2. ??android?:name=".ArtistActivity"???????? ??
  3. ??android?:label="Artist"???????? ??
  4. ??android?:launchMode="singleTop">???? ??
  5. ??</activity>? ??
  6. ??
  7. Intent?i?=?new?Intent();???????? ??
  8. ???i.putExtra(EXTRA_KEY_ARTIST,?id);??????? ??
  9. ????i.setClass(this,?ArtistActivity.class);???????? ??
  10. ????i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);??????? ??
  11. ?????startActivity(i);???

9.´´½¨Ò»¸öÔ²½ÇͼƬ
Õâ¸öµÄÖ÷ÒªÔ­ÀíÆäʵ¾ÍÊÇÀûÓÃÕÚÕÖ£¬ÏÈ´´½¨Ò»¸öÔ²½Ç·½¿ò È»ºó½«Í¼Æ¬·ÅÔÚÏÂÃ棺

Java´úÂë
  1. Bitmap?myCoolBitmap?=?...?;? ??
  2. ??????int?w?=?myCoolBitmap.getWidth(),?h?=?myCoolBitmap.getHeight();? ??
  3. ??????Bitmap?rounder?=?Bitmap.createBitmap(w,h,Bitmap.Config.ARGB_8888);? ??
  4. ??????Canvas?canvas?=?new?Canvas(rounder);???? ??
  5. ??????Paint?xferPaint?=?new?Paint(Paint.ANTI_ALIAS_FLAG);? ??
  6. ??????xferPaint.setColor(Color.RED);? ??
  7. ??????canvas.drawRoundRect(new?RectF(0,0,w,h),?20.0f,?20.0f,?xferPaint);????? ??
  8. ??????xferPaint.setXfermode(new?PorterDuffXfermode(PorterDuff.Mode.DST_IN));???
Java´úÂë
  1. //È»ºóÄØʵÏÖ? ??
  2. canvas.drawBitmap(myCoolBitmap,?0,0,?null);? ??
  3. canvas.drawBitmap(rounder,?0,?0,?xferPaint);? ??

10.ÔÚnotification ÉϵÄiconÉϼÓÉÏÊý×Ö ¸øÈËÌáʾÓжàÉÙ¸öδ¶Á

Java´úÂë
  1. Notification?notification?=?new?Notification?(icon,?tickerText,?when);? ??
  2. notification?.number?=?4;???

11±³¾°½¥±ä£º
Ê×ÏȽ¨Á¢Îļþdrawable/shape.xml

Java´úÂë
  1. <?xml?version="1.0"?encoding="utf-8"?>? ??
  2. <shape?xmlns:android?="http://schemas.android?.com/apk/res/android?"?android?:shape="rectangle">? ??
  3. ????<gradient?android?:startColor="#FFFFFFFF"?android?:endColor="#FFFF0000"? ??
  4. ????????????android?:angle="270"/>? ??
  5. </shape>? ??

ÔÚ¸ÃÎļþÖÐÉèÖý¥±äµÄ¿ªÊ¼ÑÕÉ«(startColor)¡¢½áÊøÑÕÉ«(endColor)ºÍ½Ç¶È(angle)

½Ó×Å´´½¨Ò»¸öÖ÷Ìâvalues/style.xml

Java´úÂë
  1. <?xml?version="1.0"?encoding="utf-8"?>? ??
  2. <resources>? ??
  3. <style?name="NewTheme"?parent="android?:Theme">? ??
  4. <item?name="android?:background">@drawable/shape</item>? ??
  5. </style>? ??
  6. </resources>???

È»ºóÔÚAndroidManifest.xmlÎļþÖеÄapplication»òactivityÖÐÒýÈë¸ÃÖ÷Ìâ,Èç:

Java´úÂë
  1. <activity?android?:name=".ShapeDemo"?android?:theme="@style/NewTheme">? ??

¸Ã·½·¨Í¬ÑùÊÊÓÃÓڿؼþ

<?php xml version="1.0" ?>
?
<response>
<error>1</error>
<message>Invalid URL.</message>
</response>

12. ´¢´æÊý¾Ý µ±ÄãÔÚÒ»¸öʵÀýÖб£´æ¾²Ì¬Êý¾Ý£¬´ËʾÀý¹Ø±Õºó ÏÂÒ»¸öʵÀýÏëÒýÓà ¾²Ì¬Êý¾Ý¾Í»áΪnull£¬ÕâÀïÄرØÐëÖØдapplition

Java´úÂë
  1. public?class?MyApplication?extends?Application{???? ??
  2. ???private?String?thing?=?null;???? ??
  3. ???public?String?getThing(){???????? ??
  4. ?????return?thing;???? ??
  5. ?????}???? ??
  6. ?????public?void?setThing(?String?thing?){??????? ??
  7. ??????this.thing?=?thing;????}? ??
  8. ??????}? ??
  9. ??????public?class?MyActivity?extends?Activity?{???? ??
  10. ??????private?MyApplication?app;???? ??
  11. ??????public?void?onCreate(Bundle?savedInstanceState)?{???????? ??
  12. ??????super.onCreate(savedInstanceState);???????? ??
  13. ??????app?=?((MyApplication)getApplication());???????? ??
  14. ??????String?thing?=?app.getThing();???? ??
  15. ??????}? ??
  16. ??????}
  Ïà¹Ø½â¾ö·½°¸