-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1791 lines (835 loc) · 76.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html class="theme-next mist use-motion">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>
<link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />
<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />
<meta name="keywords" content="Hexo, NexT" />
<link rel="alternate" href="/atom.xml" title="Tiny Space" type="application/atom+xml" />
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />
<meta name="description" content="学习总结 习惯养成 个人信仰">
<meta property="og:type" content="website">
<meta property="og:title" content="Tiny Space">
<meta property="og:url" content="http://dengbo22.github.io/index.html">
<meta property="og:site_name" content="Tiny Space">
<meta property="og:description" content="学习总结 习惯养成 个人信仰">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Tiny Space">
<meta name="twitter:description" content="学习总结 习惯养成 个人信仰">
<script type="text/javascript" id="hexo.configuration">
var NexT = window.NexT || {};
var CONFIG = {
scheme: 'Mist',
sidebar: {"position":"left","display":"post"},
fancybox: true,
motion: true,
duoshuo: {
userId: 0,
author: '博主'
}
};
</script>
<title> Tiny Space </title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left
page-home
">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">Tiny Space</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">言念君子,温其如玉。</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-home fa-fw"></i> <br />
首页
</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories" rel="section">
<i class="menu-item-icon fa fa-th fa-fw"></i> <br />
分类
</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about" rel="section">
<i class="menu-item-icon fa fa-user fa-fw"></i> <br />
关于
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives" rel="section">
<i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
归档
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags" rel="section">
<i class="menu-item-icon fa fa-tags fa-fw"></i> <br />
标签
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/04/18/Android-消息通讯-Handler和Looper与MessageQueue的恩怨情仇/" itemprop="url">
Handler和Looper与MessageQueue的恩怨情仇
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-04-18T17:16:32+08:00" content="2016-04-18">
2016-04-18
</time>
</span>
<span class="post-category" >
|
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="https://schema.org/Thing">
<a href="/categories/programming/" itemprop="url" rel="index">
<span itemprop="name">编程笔记</span>
</a>
</span>
</span>
<span class="post-comments-count">
|
<a href="/2016/04/18/Android-消息通讯-Handler和Looper与MessageQueue的恩怨情仇/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/04/18/Android-消息通讯-Handler和Looper与MessageQueue的恩怨情仇/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>Message是Android中最为常用的消息通讯机制,这种机制是建立在Handler、Looper和MessageQueue的分工协作上。Message通过Handler分发到MessageQueue中,MessageQueue将所有的Message组织成一个链表,通过Looper不断的将MessageQueue中的Message取出,取出以后又交付给对应的Handler来处理,从而完成一整套消息通讯机制。<br>
<div class="post-more-link text-center">
<a class="btn" href="/2016/04/18/Android-消息通讯-Handler和Looper与MessageQueue的恩怨情仇/#more" rel="contents">
阅读全文 »
</a>
</div>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2016/03/03/Python内核分析——基本类型/" itemprop="url">
Python内核分析——基本类型
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2016-03-03T12:09:31+08:00" content="2016-03-03">
2016-03-03
</time>
</span>
<span class="post-comments-count">
|
<a href="/2016/03/03/Python内核分析——基本类型/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2016/03/03/Python内核分析——基本类型/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="Python基本对象">Python基本对象</h2><p>python中所有东西都是对象,而所有对象都拥有的相同的内容,就是PyObject中的内容:<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> _object {</span><br><span class="line"> <span class="keyword">int</span> ob_refcnt; <span class="comment">//对象的引用计数</span></span><br><span class="line"> <span class="keyword">struct</span> _typeobject *ob_type; <span class="comment">//对象的类型指针</span></span><br><span class="line">} PyObject</span><br></pre></td></tr></table></figure></p>
<p>在此基础上,由于一些变量的长度是可变的,那么对于这些变量,则需要另一个结构体来储存,这就是PyVarObject。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> PyObject_VAR_HEAD {</span><br><span class="line"> <span class="keyword">int</span> ob_refcnt;</span><br><span class="line"> <span class="keyword">struct</span> _typeobject *ob_type;</span><br><span class="line"> <span class="keyword">int</span> ob_size; <span class="comment">//保存的元素的个数而非字节数</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<p>其中,对于上面两个结构体而言,都有_typeobject的指针,其具体实现如下<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> _typeobject {</span><br><span class="line"> PyObject_VAR_HEAD</span><br><span class="line"> <span class="keyword">char</span> *tp_name; <span class="comment">/*类型的名称*/</span></span><br><span class="line"> <span class="keyword">int</span> tp_basicsize, <span class="comment">//类型大小,用于申请内存</span></span><br><span class="line"> tp_itemsize; <span class="comment">//表示每个元素所占的字节数</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">/*以下为函数指针,用于函数操作*/</span></span><br><span class="line"> destructor tp_dealloc; <span class="comment">//对象析构函数指针</span></span><br><span class="line"> printfunc tp_print; <span class="comment">//打印函数</span></span><br><span class="line"> <span class="comment">/*其他标准操作*/</span></span><br><span class="line"> hashfunc tp_hash; <span class="comment">//哈希操作函数</span></span><br><span class="line"> ......</span><br><span class="line">} PyTypeObject;</span><br></pre></td></tr></table></figure></p>
<div class="post-more-link text-center">
<a class="btn" href="/2016/03/03/Python内核分析——基本类型/#more" rel="contents">
阅读全文 »
</a>
</div>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2015/12/16/Android列表控件RecyclerView/" itemprop="url">
Android列表控件RecyclerView
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2015-12-16T21:44:58+08:00" content="2015-12-16">
2015-12-16
</time>
</span>
<span class="post-comments-count">
|
<a href="/2015/12/16/Android列表控件RecyclerView/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2015/12/16/Android列表控件RecyclerView/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>RecyclerView中的相关类:<br>RecyclerView.Adapter: 可以托管数据集合,为每一项Item创建视图并且绑定数据<br>RecyclerView.ViewHolder: 承载Item视图的子布局<br>RecyclerView.LayoutManager: 负责Item视图的布局的显示管理<br>RecyclerView.ItemDecoration: 给每一项Item视图添加子View,例如可以进行画分隔线之类的<br>RecyclerView.ItemAnimator: 负责处理数据添加或者删除时候的动画效果</p>
<div class="post-more-link text-center">
<a class="btn" href="/2015/12/16/Android列表控件RecyclerView/#more" rel="contents">
阅读全文 »
</a>
</div>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2015/10/07/Ubuntu下的Sublime安装/" itemprop="url">
Ubuntu下的Sublime安装
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2015-10-07T17:30:50+08:00" content="2015-10-07">
2015-10-07
</time>
</span>
<span class="post-category" >
|
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="https://schema.org/Thing">
<a href="/categories/operating-system/" itemprop="url" rel="index">
<span itemprop="name">操作系统</span>
</a>
</span>
</span>
<span class="post-comments-count">
|
<a href="/2015/10/07/Ubuntu下的Sublime安装/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2015/10/07/Ubuntu下的Sublime安装/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="安装:">安装:</h2><p>使用apt安装(sublime-text-2)<br>sudo add-apt-repository ppa:webupd8team/sublime-text-2<br>sudo apt-get update<br>sudo apt-get install sublime-text</p>
<h2 id="添加包管理工具">添加包管理工具</h2><ul>
<li><p>Sublime-Text-2<br>按下`ctrl + ``来打开Sublime Text Console,输入一下代码:</p>
<figure class="highlight lasso"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> urllib2,os,hashlib;</span><br><span class="line">h = <span class="string">'2915d1851351e5ee549c20394736b442'</span> + <span class="string">'8bc59f460fa1548d1514676163dafc88'</span>;</span><br><span class="line">pf = <span class="string">'Package Control.sublime-package'</span>;</span><br><span class="line">ipp = sublime<span class="built_in">.</span>installed_packages_path();</span><br><span class="line">os<span class="built_in">.</span>makedirs( ipp ) <span class="keyword">if</span> <span class="subst">not</span> os<span class="built_in">.</span>path<span class="built_in">.</span>exists(ipp) <span class="keyword">else</span> <span class="literal">None</span>;</span><br><span class="line">urllib2<span class="built_in">.</span>install_opener( urllib2<span class="built_in">.</span>build_opener( urllib2<span class="built_in">.</span>ProxyHandler() ) );</span><br><span class="line"><span class="keyword">by</span> = urllib2<span class="built_in">.</span>urlopen( <span class="string">'http://packagecontrol.io/'</span> + pf<span class="built_in">.</span>replace(<span class="string">' '</span>, <span class="string">'%20'</span>) )<span class="built_in">.</span>read();</span><br><span class="line">dh = hashlib<span class="built_in">.</span>sha256(<span class="keyword">by</span>)<span class="built_in">.</span>hexdigest();</span><br><span class="line">open( os<span class="built_in">.</span>path<span class="built_in">.</span><span class="keyword">join</span>( ipp, pf ), <span class="string">'wb'</span> )<span class="built_in">.</span>write(<span class="keyword">by</span>) <span class="keyword">if</span> dh == h <span class="keyword">else</span> <span class="literal">None</span>;</span><br><span class="line">print(<span class="string">'Error validating download (got %s instead of %s), please try manual install'</span> % (dh, h)</span><br><span class="line"><span class="keyword">if</span> dh != h <span class="keyword">else</span> <span class="string">'Please restart Sublime Text to finish installation'</span>)</span><br></pre></td></tr></table></figure>
</li>
<li><p>Sublime Text 3<br>同样,按下`ctrl + ``来打开Sublime Text Console后,输入一下代码:</p>
<figure class="highlight openscad"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">import</span> urllib.request,os,hashlib;</span><br><span class="line">h = '<span class="number">2915</span>d1851351e5ee549c20394736b442' + '<span class="number">8</span>bc59f460fa1548d1514676163dafc88';</span><br><span class="line">pf = 'Package Control.sublime-package';</span><br><span class="line">ipp = sublime.installed_packages_path<span class="params">()</span>;</span><br><span class="line">urllib.request.install_opener<span class="params">( urllib.request.build_opener<span class="params">( urllib.request.ProxyHandler<span class="params">()</span> )</span> )</span>;</span><br><span class="line">by = urllib.request.urlopen<span class="params">( 'http://packagecontrol.io/' + pf.replace<span class="params">(' ', '%<span class="number">20</span>')</span> )</span>.read<span class="params">()</span>;</span><br><span class="line">dh = hashlib.sha256<span class="params">(by)</span>.hexdigest<span class="params">()</span>;</span><br><span class="line">print<span class="params">('Error validating download <span class="params">(got %s instead of %s)</span>, please try manual install' % <span class="params">(dh, h)</span>)</span></span><br><span class="line"><span class="keyword">if</span> dh <span class="built_in">!</span>= h <span class="keyword">else</span> open<span class="params">(os.path.join<span class="params">( ipp, pf )</span>, 'wb' )</span>.write<span class="params">(by)</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="使用包管理工具安装插件">使用包管理工具安装插件</h2>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2015/09/23/Android屏幕适配/" itemprop="url">
Android屏幕适配
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2015-09-23T19:21:38+08:00" content="2015-09-23">
2015-09-23
</time>
</span>
<span class="post-category" >
|
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="https://schema.org/Thing">
<a href="/categories/programming/" itemprop="url" rel="index">
<span itemprop="name">编程笔记</span>
</a>
</span>
</span>
<span class="post-comments-count">
|
<a href="/2015/09/23/Android屏幕适配/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2015/09/23/Android屏幕适配/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h2 id="1-_Android屏幕适配分辨率">1. Android屏幕适配分辨率 </h2><p>常见需要适配的屏幕分辨率有<strong>1280 x 720</strong>、<strong>800 x 480</strong>、<strong>854 x 480</strong>、<strong>1920 x 1080</strong>、<strong>960 x 540</strong>、<strong>480 x 320</strong>.</p>
<h2 id="2-_密度无关像素:dot_per">2. 密度无关像素:dot per</h2><p> inch(dpi):<strong>其值与屏幕尺寸和屏幕分辨率有关。</strong>以密度无关像素对设备进行区分,大致分为如下几类:(括号内为图片放缩比例)</p>
<ul>
<li>mdpi ( x 1) —— 120 ~160 dpi</li>
<li>hdpi ( x1.5) —— 160 ~240 dpi</li>
<li>xhdpi( x 2) —— 240 ~320 dpi</li>
<li>xxhdpi(x 3) —— 320 ~ 480 dpi</li>
<li>xxxhdpi(x 4) —— 480 ~ 640 dpi </li>
</ul>
<blockquote>
<p>Ps:以Nexus 5为例。屏幕分辨率1920x1080,对角分辨率P =sqrt(1920^2+1080^2)=2202。使用对角分辨率除以屏幕尺寸4.95英寸即可得到密度无关像素(DPI)为445dpi.</p>
</blockquote>
<h2 id="3-_文字大小">3. 文字大小 </h2><p>推荐使用<strong>12sp</strong>以上的字体大小,并且推荐大小为<strong>12/14/18/22sp</strong>的字体,并且尽量不要使用奇数和小数,其容易在放大或缩小过程中导致精度丢失。</p>
<h2 id="4-_限定符(尺寸限定符和方向限定符可以连着使用)">4. 限定符(尺寸限定符和方向限定符可以连着使用) </h2><ul>
<li><p>尺寸限定符<br>创建不同的文件夹,在不同的文件夹下创建相同的文件,使用不同的方式进行应用:<br>res/layout/main.xml —— 常规文件<br>res/layout-large/main.xml —— Android 3.2版本前平板等设备使用的layout<br>res/layout-sw600dp/main.xml —— Android 3.2版本以后等设备使用的layout,指最小宽度大于600dp的设备(一般即指平板)</p>
<blockquote>
<p>小技巧:<br>对于以上情况可以使用<strong>布局别名</strong><br>创建两个文件:<br>res/layout/main_vertical.xml —— 竖直状态布局<br>res/layout/main_oriental.xml ——水平状态布局</p>
<p><strong>默认布局:res/values/layout.xml</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">resources</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">item</span> <span class="attribute">name</span>=<span class="value">"main"</span> <span class="attribute">type</span>=<span class="value">"layout"</span>></span>@layout/main_vertical.xml<span class="tag"></<span class="title">item</span>></span></span><br><span class="line"><span class="tag"></<span class="title">resources</span>></span></span><br></pre></td></tr></table></figure>
</blockquote>
</li>
</ul>
<blockquote>
<p><strong>Android 3.2版本前的布局:res/values-large/layouts.xml</strong><br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">resources</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">item</span> <span class="attribute">name</span>=<span class="value">"main"</span> <span class="attribute">type</span>=<span class="value">"layout"</span>></span>@layout/main_oriental.xml<span class="tag"></<span class="title">item</span>></span></span><br><span class="line"><span class="tag"></<span class="title">resources</span>></span></span><br></pre></td></tr></table></figure></p>
<p><strong>Android 3.2版本后的布局:res/values-sw600dp/layouts.xml</strong><br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">resources</span>></span></span><br><span class="line"> <span class="tag"><<span class="title">item</span> <span class="attribute">name</span>=<span class="value">"main"</span> <span class="attribute">type</span>=<span class="value">"layout"</span>></span>@layout/main_oriental.xml<span class="tag"></<span class="title">item</span>></span></span><br><span class="line"><span class="tag"></<span class="title">resources</span>></span></span><br></pre></td></tr></table></figure></p>
<p>在对应的Activity中只需要setContentView(R.layout.main)即可</p>
</blockquote>
<ul>
<li><p>方向限定符<br><strong>land / port </strong><br>与尺寸限定符类似,创建对应的layouts.xml文件<br>res/values-land/layouts.xml<br>res/values-port/layouts.xml<br>之后同上创建<resources>标签来指定对应的布局文件</resources></p>
</li>
<li><p>9-patch图<br>左侧和上侧用于标记可拉伸的位置,实际拉伸由点的数量按照比例进行拉伸。<br>右侧和下侧用于标记,未被标记的区段将会被设置成padding值</p>
</li>
</ul>
<h2 id="5-组件布局:">5.组件布局: </h2><p>可以使用Android提供的百分比布局库:android-percent-support-lib,其使用百分比的方式进行Layout布局,主要支持<strong>PercentRelativeLayout</strong>和<strong>PercentFrameLayout</strong><br>支持的属性有:<br>layout_widthPercent、layout_heightPercent<br>layout_marginPercent、layout_marginLeftPercent、layout_marginRightPercent等6个属性</p>
<blockquote>
<p>gradle添加:compile ‘com.android.support:percent:22.2.0’ </p>
</blockquote>
<p>小例子:<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="title">android.support.percent.PercentFrameLayout</span></span><br><span class="line"> <span class="attribute">xmlns:android</span>=<span class="value">"http://schemas.android.com/apk/res/android"</span></span><br><span class="line"> <span class="attribute">xmlns:app</span> = "<span class="attribute">http:</span>//<span class="attribute">schemas.android.com</span>/<span class="attribute">apk</span>/<span class="attribute">res-auto</span>"</span><br><span class="line"> <span class="attribute">android:layout_width</span> = "<span class="attribute">match_parent</span>"</span><br><span class="line"> <span class="attribute">android:layout_height</span>= "<span class="attribute">match_parent</span>"</span><br><span class="line"> ></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="title">TextView</span></span><br><span class="line"> <span class="attribute">android:layout_width</span> = "<span class="attribute">0dp</span>"</span><br><span class="line"> <span class="attribute">android:layout_height</span> = "<span class="attribute">0dp</span>"</span><br><span class="line"> <span class="attribute">app:layout_heightPercent</span> = "<span class="attribute">20</span>%"</span><br><span class="line"> <span class="attribute">app:layout_widthPercent</span> = "<span class="attribute">30</span>%"</span><br><span class="line"> <span class="attribute">android:layout_gravity</span> = " "</span><br><span class="line"> /></span></span><br><span class="line"></span><br><span class="line"><span class="tag"></<span class="title">android.support.percent.PercentFrameLayout</span>></span></span><br></pre></td></tr></table></figure></p>
<blockquote>
<p>Tips:</p>
<ul>
<li>需要指定xmlns,即:xmlns:app=”<a href="http://schemas.android.com/apk/res-auto" target="_blank" rel="external">http://schemas.android.com/apk/res-auto</a>“</li>
<li>内部的控件大小需要设定为0dp,之后才会按照percent来进行划分,类似于weight</li>
<li>对于FrameLayout而言,内部控件放置类似于LinearLayout,而PercentRelatvieLayout与RelativeLayout类似</li>
</ul>
</blockquote>
<p>参考资料:<br><a href="http://blog.csdn.net/lmj623565791/article/details/46695347" target="_blank" rel="external">http://blog.csdn.net/lmj623565791/article/details/46695347</a></p>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2015/09/19/Android的View绘制过程/" itemprop="url">
Android的View绘制过程
</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time itemprop="dateCreated" datetime="2015-09-19T15:50:38+08:00" content="2015-09-19">
2015-09-19
</time>
</span>
<span class="post-category" >
|
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="https://schema.org/Thing">
<a href="/categories/programming/" itemprop="url" rel="index">
<span itemprop="name">编程笔记</span>
</a>
</span>
</span>
<span class="post-comments-count">
|
<a href="/2015/09/19/Android的View绘制过程/#comments" itemprop="discussionUrl">
<span class="post-comments-count ds-thread-count" data-thread-key="2015/09/19/Android的View绘制过程/" itemprop="commentsCount"></span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>众所周知,View的绘制过程从ViewRootImpl.performTraversals()方法开始。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//以下位ViewRootImpl的成员变量</span></span><br><span class="line"><span class="keyword">final</span> Rect mWinFrame; <span class="comment">//frame given by window manager</span></span><br><span class="line"><span class="keyword">int</span> mWidth = mWinFrame.width();</span><br><span class="line"><span class="keyword">int</span> mHeight = mWinFrame.height();</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">performTraversals</span><span class="params">()</span> </span>{</span><br><span class="line"> WindowManager.LayoutParams lp = mWindowAttributes;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//是否需要进行Measure</span></span><br><span class="line"> <span class="keyword">if</span>( !mStopped ) {</span><br><span class="line"> <span class="comment">//获得更是图mView(即DecorView)的尺寸</span></span><br><span class="line"> <span class="keyword">int</span> childWidthMeasureSpec = getRootMeasureSpec( mWidth, lp.width);</span><br><span class="line"> <span class="keyword">int</span> childHeightMeasureSpec = getRootMeasureSpec( mHeight, lp.height);</span><br><span class="line"> performMeasure( childWidthMeasureSpec, childHeightMeasureSpec);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// ....</span></span><br><span class="line"> <span class="comment">//是否需要执行Layout</span></span><br><span class="line"> <span class="keyword">final</span> <span class="keyword">boolean</span> didLayout = layoutRequested && !mStopped;</span><br><span class="line"> <span class="keyword">if</span>( didLayout ) {</span><br><span class="line"> performLayout( lp, desireWindowWidth, desiredWindowHeight);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//...</span></span><br><span class="line"> <span class="comment">//是否需要Draw</span></span><br><span class="line"> <span class="keyword">if</span>( !cancelDraw && !newSurface ) {</span><br><span class="line"> performDraw();</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> scheduleTraversals();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></p>
<p>从上我们可以看出来,View的绘制过程大体需要进行三大步骤:<br>1.measure —— 确定每一个View的长度和宽度。<br>2.layout —— 确定每一个View所应该摆放的位置。<br>3.draw —— 根据每一个View大小来绘制内容。</p>
<div class="post-more-link text-center">
<a class="btn" href="/2015/09/19/Android的View绘制过程/#more" rel="contents">
阅读全文 »
</a>
</div>
</div>
<div>
</div>
<div>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</article>
<article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">