av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Android界面設(shè)計(jì)基礎(chǔ):控件焦點(diǎn)4個(gè)步驟

Android設(shè)備有多種多樣,操縱界面也有所不同,比如有觸摸屏、軌跡球,傳統(tǒng)的手機(jī)鍵盤(pán)等,因此開(kāi)發(fā)者需要更好地了解,當(dāng)用戶在應(yīng)用程序界面中的不同控件間移動(dòng)時(shí),各個(gè)控件的獲得焦點(diǎn)和失去焦點(diǎn)的順序,以及如何根據(jù)用戶的操作習(xí)慣去自定義這些順序。

成都創(chuàng)新互聯(lián)公司專(zhuān)注于周口網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供周口營(yíng)銷(xiāo)型網(wǎng)站建設(shè),周口網(wǎng)站制作、周口網(wǎng)頁(yè)設(shè)計(jì)、周口網(wǎng)站官網(wǎng)定制、小程序定制開(kāi)發(fā)服務(wù),打造周口網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供周口網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。

一般情況下,Android對(duì)于特定的布局界面,會(huì)自動(dòng)得出一個(gè)合適的控件焦點(diǎn)順序,很多情況下是足夠用的了。但是在有的情況下是有例外的??丶南乱粋€(gè)焦點(diǎn)會(huì)到達(dá)哪一個(gè)控件,主要是判斷當(dāng)前控件在指定的方向布局上(up/down/left/right),哪一個(gè)是最領(lǐng)近的控件,其掃描順序?yàn)閺淖蟮接?,從上到下,就象平時(shí)閱讀書(shū)籍一樣。

然而,這種順序有時(shí)會(huì)帶來(lái)一點(diǎn)小問(wèn)題,比如當(dāng)控件都布置在屏幕的上方時(shí),如果用戶再按“up”鍵,則不會(huì)有任何效果,同樣,當(dāng)控件都在屏幕下方、左邊、右邊時(shí),此時(shí)再按如“down”、“Left”,“Right”鍵時(shí)都不會(huì)再獲得控件的焦點(diǎn)。

在本文的例子中,將講解如何修改默認(rèn)的控件焦點(diǎn)順序,以定制特定的控件切換順序,例子中,多個(gè)按鈕以一個(gè)圓形進(jìn)行了排列,例子可以在

http://android-mt-tutorials.googlecode.com/svn/trunk/SimpleFocus中下載。

步驟1 定義界面布局

我們先設(shè)計(jì)出界面的布局,代碼如下,使用的是Relative相對(duì)布局:

 
 
 
  1.  
  2.     xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent"> 
  5.     
  6.         style="@style/clockFaceNum" 
  7.         android:text="12" 
  8.         android:id="@+id/button12" 
  9.         android:layout_alignParentTop="true" 
  10.         android:layout_centerHorizontal="true"> 
  11.      
  12.     
  13.         style="@style/clockFaceNum" 
  14.         android:text="11" 
  15.         android:id="@+id/button11" 
  16.         android:layout_below="@+id/button12" 
  17.         android:layout_toLeftOf="@+id/button12"> 
  18.      
  19.     
  20.         style="@style/clockFaceNum" 
  21.         android:text="1" 
  22.         android:id="@+id/button1" 
  23.         android:layout_below="@+id/button12" 
  24.         android:layout_toRightOf="@+id/button12"> 
  25.      
  26.     
  27.         style="@style/clockFaceNum" 
  28.         android:text="10" 
  29.         android:id="@+id/button10" 
  30.         android:layout_below="@+id/button11" 
  31.         android:layout_toLeftOf="@+id/button11"> 
  32.      
  33.     
  34.         style="@style/clockFaceNum" 
  35.         android:text="2" 
  36.         android:id="@+id/button2" 
  37.         android:layout_below="@+id/button1" 
  38.         android:layout_toRightOf="@+id/button1"> 
  39.      
  40.     
  41.         style="@style/clockFaceNum" 
  42.         android:text="9" 
  43.         android:id="@+id/button9" 
  44.         android:layout_below="@+id/button10" 
  45.         android:layout_toLeftOf="@+id/button10"> 
  46.      
  47.  
  48.     
  49.         style="@style/clockFaceNum" 
  50.         android:text="3" 
  51.         android:id="@+id/button3" 
  52.         android:layout_below="@+id/button2" 
  53.         android:layout_toRightOf="@+id/button2"> 
  54.      
  55.     
  56.         style="@style/clockFaceNum" 
  57.         android:text="8" 
  58.         android:id="@+id/button8" 
  59.         android:layout_below="@+id/button9" 
  60.         android:layout_toRightOf="@+id/button9"> 
  61.      
  62.     
  63.         style="@style/clockFaceNum" 
  64.         android:text="4" 
  65.         android:id="@+id/button4" 
  66.         android:layout_below="@+id/button3" 
  67.         android:layout_toLeftOf="@+id/button3"> 
  68.      
  69.     
  70.         style="@style/clockFaceNum" 
  71.         android:text="7" 
  72.         android:id="@+id/button7" 
  73.         android:layout_below="@+id/button8" 
  74.         android:layout_toRightOf="@+id/button8"> 
  75.      
  76.     
  77.         style="@style/clockFaceNum" 
  78.         android:text="5" 
  79.         android:id="@+id/button5" 
  80.         android:layout_below="@+id/button4" 
  81.         android:layout_toLeftOf="@+id/button4"> 
  82.      
  83.     
  84.         style="@style/clockFaceNum" 
  85.         android:text="6" 
  86.         android:id="@+id/button6" 
  87.         android:layout_below="@+id/button5" 
  88.         android:layout_centerHorizontal="true"> 
  89.      
  90.  
  91.   

 上面定義的style文件如下:

 
 
 
  1.  
  2.  
  3.     
  4.         name="clockFaceNum"> 
  5.         
  6.             name="android:layout_width">38dp 
  7.         
  8.             name="android:layout_height">38dp 
  9.         
  10.             name="android:onClick">numClicked 
  11.         
  12.             name="android:textSize">9sp 
  13.      
  14.  

運(yùn)行后,效果如下圖:

步驟2 默認(rèn)的控件焦點(diǎn)切換順序

比如當(dāng)用戶將控件焦點(diǎn)點(diǎn)在12號(hào)按鈕時(shí),點(diǎn)往下的“down”按鈕,默認(rèn)的控件焦點(diǎn)切換順序如下圖:

也就是說(shuō),當(dāng)在按鈕12上往下按的時(shí)候,控件的焦點(diǎn)會(huì)切換到11,接著就是鍵10,如此類(lèi)推。

步驟3 創(chuàng)建自定義的控件焦點(diǎn)順序

下面,我們嘗試創(chuàng)建自定義的控件焦點(diǎn)順序,即同時(shí)允許在上面的界面中,當(dāng)用戶按鍵時(shí),以順時(shí)針或逆時(shí)針進(jìn)行控件切換,如下圖:

也就是說(shuō),允許用戶當(dāng)按“Down”或“Right”鍵時(shí),切換順序是順時(shí)針?lè)较?,比如假設(shè)當(dāng)前在鍵12上,按“Down”或“Right”鍵時(shí),會(huì)切換到鍵1,而按“Up”或”Left”時(shí),會(huì)切換到鍵11,如此類(lèi)推。要實(shí)現(xiàn)這點(diǎn),可以在每個(gè)按鈕中進(jìn)行設(shè)置如下四個(gè)屬性:

android:nextFocusUp- 定義當(dāng)點(diǎn)up鍵時(shí),哪個(gè)控件將獲得焦點(diǎn)

android:nextFocusDown-定義當(dāng)點(diǎn)down鍵時(shí),哪個(gè)控件將獲得焦點(diǎn)

android:nextFocusLeft-定義當(dāng)點(diǎn)left鍵時(shí),哪個(gè)控件將獲得焦點(diǎn)

android:nextFocusRight--定義當(dāng)點(diǎn)right鍵時(shí),哪個(gè)控件將獲得焦點(diǎn)

下面是其代碼:

 
 
 
  1.  
  2.     xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent"> 
  5.     
  6.         style="@style/clockFaceNum" 
  7.         android:text="12" 
  8.         android:id="@+id/button12" 
  9.         android:layout_alignParentTop="true" 
  10.         android:layout_centerHorizontal="true" 
  11.         android:nextFocusUp="@+id/button11" 
  12.         android:nextFocusLeft="@+id/button11" 
  13.         android:nextFocusRight="@+id/button1" 
  14.         android:nextFocusDown="@+id/button1"> 
  15.      
  16.     
  17.         style="@style/clockFaceNum" 
  18.         android:text="11" 
  19.         android:id="@+id/button11" 
  20.         android:layout_below="@+id/button12" 
  21.         android:layout_toLeftOf="@+id/button12" 
  22.         android:nextFocusUp="@+id/button10" 
  23.         android:nextFocusLeft="@+id/button10" 
  24.         android:nextFocusRight="@+id/button12" 
  25.         android:nextFocusDown="@+id/button12"> 
  26.      
  27.     
  28.         style="@style/clockFaceNum" 
  29.         android:text="1" 
  30.         android:id="@+id/button1" 
  31.         android:layout_below="@+id/button12" 
  32.         android:layout_toRightOf="@+id/button12" 
  33.         android:nextFocusUp="@+id/button12" 
  34.         android:nextFocusLeft="@+id/button12" 
  35.         android:nextFocusRight="@+id/button2" 
  36.         android:nextFocusDown="@+id/button2"> 
  37.      
  38.     
  39.         style="@style/clockFaceNum" 
  40.         android:text="10" 
  41.         android:id="@+id/button10" 
  42.         android:layout_below="@+id/button11" 
  43.         android:layout_toLeftOf="@+id/button11" 
  44.         android:nextFocusUp="@+id/button9" 
  45.         android:nextFocusLeft="@+id/button9" 
  46.         android:nextFocusRight="@+id/button11" 
  47.         android:nextFocusDown="@+id/button11"> 
  48.      
  49.     
  50.         style="@style/clockFaceNum" 
  51.         android:text="2" 
  52.         android:id="@+id/button2" 
  53.         android:layout_below="@+id/button1" 
  54.         android:layout_toRightOf="@+id/button1" 
  55.         android:nextFocusUp="@+id/button1" 
  56.         android:nextFocusLeft="@+id/button1" 
  57.         android:nextFocusRight="@+id/button3" 
  58.         android:nextFocusDown="@+id/button3"> 
  59.      
  60.     
  61.         style="@style/clockFaceNum" 
  62.         android:text="9" 
  63.         android:id="@+id/button9" 
  64.         android:layout_below="@+id/button10" 
  65.         android:layout_toLeftOf="@+id/button10" 
  66.         android:nextFocusUp="@+id/button8" 
  67.         android:nextFocusLeft="@+id/button8" 
  68.         android:nextFocusRight="@+id/button10" 
  69.         android:nextFocusDown="@+id/button10"> 
  70.      
  71.  
  72.     
  73.         style="@style/clockFaceNum" 
  74.         android:text="3" 
  75.         android:id="@+id/button3" 
  76.         android:layout_below="@+id/button2" 
  77.         android:layout_toRightOf="@+id/button2" 
  78.         android:nextFocusUp="@+id/button2" 
  79.         android:nextFocusLeft="@+id/button2" 
  80.         android:nextFocusRight="@+id/button4" 
  81.         android:nextFocusDown="@+id/button4"> 
  82.      
  83.     
  84.         style="@style/clockFaceNum" 
  85.         android:text="8" 
  86.         android:id="@+id/button8" 
  87.         android:layout_below="@+id/button9" 
  88.         android:layout_toRightOf="@+id/button9" 
  89.         android:nextFocusUp="@+id/button7" 
  90.         android:nextFocusLeft="@+id/button7" 
  91.         android:nextFocusRight="@+id/button9" 
  92.         android:nextFocusDown="@+id/button9"> 
  93.      
  94.     
  95.         style="@style/clockFaceNum" 
  96.         android:text="4" 
  97.         android:id="@+id/button4" 
  98.         android:layout_below="@+id/button3" 
  99.         android:layout_toLeftOf="@+id/button3" 
  100.         android:nextFocusUp="@+id/button3" 
  101.         android:nextFocusLeft="@+id/button3" 
  102.         android:nextFocusRight="@+id/button5" 
  103.         android:nextFocusDown="@+id/button5"> 
  104.      
  105.     
  106.         style="@style/clockFaceNum" 
  107.         android:text="7" 
  108.         android:id="@+id/button7" 
  109.         android:layout_below="@+id/button8" 
  110.         android:layout_toRightOf="@+id/button8" 
  111.         android:nextFocusUp="@+id/button6" 
  112.         android:nextFocusLeft="@+id/button6" 
  113.         android:nextFocusRight="@+id/button8" 
  114.         android:nextFocusDown="@+id/button8"> 
  115.      
  116.     
  117.         style="@style/clockFaceNum" 
  118.         android:text="5" 
  119.         android:id="@+id/button5" 
  120.         android:layout_below="@+id/button4" 
  121.         android:layout_toLeftOf="@+id/button4" 
  122.         android:nextFocusUp="@+id/button4" 
  123.         android:nextFocusLeft="@+id/button4" 
  124.         android:nextFocusRight="@+id/button6" 
  125.         android:nextFocusDown="@+id/button6"> 
  126.      
  127.     
  128.         style="@style/clockFaceNum" 
  129.         android:text="6" 
  130.         android:id="@+id/button6" 
  131.         android:layout_below="@+id/button5" 
  132.         android:layout_centerHorizontal="true" 
  133.         android:nextFocusUp="@+id/button5" 
  134.         android:nextFocusLeft="@+id/button5" 
  135.         android:nextFocusRight="@+id/button7" 
  136.         android:nextFocusDown="@+id/button7"> 
  137.      
  138.  

下圖中是假定在鍵12開(kāi)始按down鍵時(shí)的焦點(diǎn)切換順序:

步驟4 設(shè)置界面的初始控件焦點(diǎn)

在每個(gè)頁(yè)面加載時(shí),可以設(shè)置界面中初始的控件焦點(diǎn),以方便用戶的定位操作,只需要在控件中加入即可。比如:

 
 
 
  1.         style="@style/clockFaceNum" 
  2.         android:text="12" 
  3.         android:id="@+id/button12" 
  4.         android:layout_alignParentTop="true" 
  5.         android:layout_centerHorizontal="true" 
  6.         android:nextFocusUp="@+id/button11" 
  7.         android:nextFocusLeft="@+id/button11" 
  8.         android:nextFocusRight="@+id/button1" 
  9.         android:nextFocusDown="@+id/button1"> 
  10.          
  11.      

小結(jié)

作為開(kāi)發(fā)者,一定要記住由于Android設(shè)備的多樣性,用戶如何在界面上方便地進(jìn)行輸入或在不同的控件中來(lái)回切換是十分重要的,本文簡(jiǎn)單介紹了用戶如何自定義控件的焦點(diǎn)切換順序,這對(duì)于用戶界面的體驗(yàn)是很有好處的。


當(dāng)前名稱(chēng):Android界面設(shè)計(jì)基礎(chǔ):控件焦點(diǎn)4個(gè)步驟
文章路徑:http://uogjgqi.cn/article/djpcjpo.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流