日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android界面設(shè)計基礎(chǔ):控件焦點4個步驟

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

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

一般情況下,Android對于特定的布局界面,會自動得出一個合適的控件焦點順序,很多情況下是足夠用的了。但是在有的情況下是有例外的??丶南乱粋€焦點會到達哪一個控件,主要是判斷當前控件在指定的方向布局上(up/down/left/right),哪一個是最領(lǐng)近的控件,其掃描順序為從左到右,從上到下,就象平時閱讀書籍一樣。

然而,這種順序有時會帶來一點小問題,比如當控件都布置在屏幕的上方時,如果用戶再按“up”鍵,則不會有任何效果,同樣,當控件都在屏幕下方、左邊、右邊時,此時再按如“down”、“Left”,“Right”鍵時都不會再獲得控件的焦點。

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

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

步驟1 定義界面布局

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

 
 
 
  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.  

運行后,效果如下圖:

步驟2 默認的控件焦點切換順序

比如當用戶將控件焦點點在12號按鈕時,點往下的“down”按鈕,默認的控件焦點切換順序如下圖:

也就是說,當在按鈕12上往下按的時候,控件的焦點會切換到11,接著就是鍵10,如此類推。

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

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

也就是說,允許用戶當按“Down”或“Right”鍵時,切換順序是順時針方向,比如假設(shè)當前在鍵12上,按“Down”或“Right”鍵時,會切換到鍵1,而按“Up”或”Left”時,會切換到鍵11,如此類推。要實現(xiàn)這點,可以在每個按鈕中進行設(shè)置如下四個屬性:

android:nextFocusUp- 定義當點up鍵時,哪個控件將獲得焦點

android:nextFocusDown-定義當點down鍵時,哪個控件將獲得焦點

android:nextFocusLeft-定義當點left鍵時,哪個控件將獲得焦點

android:nextFocusRight--定義當點right鍵時,哪個控件將獲得焦點

下面是其代碼:

 
 
 
  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開始按down鍵時的焦點切換順序:

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

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

 
 
 
  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é)

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


文章標題:Android界面設(shè)計基礎(chǔ):控件焦點4個步驟
鏈接分享:http://m.5511xx.com/article/djpcjpo.html