讀《Android電視機(機頂盒)初次開發的一些經驗分享》後的筆記

來源:互聯網
上載者:User

標籤:dpi   遙控器   實現   near   ott   htc   線性   ctf   return   

原文: http://blog.csdn.net/tanghongchang123/article/details/52982818

 

一、基本命令:

1、adb connect [ip]

2、 adb disconnect [ip]

3、adb uninstall [package]

4、.adb shell input text ****:用來輸入文字的,在偵錯工具的時候,很多情況下要鍵入文字,手機輸入方便,電視上,用遙控器按鍵盤非常麻煩的,可以用這個命令。

二、  焦點控制

1、控制控制項是否可獲得焦點

android:focusable="true/false" 當這個屬性置為true時,表示當前控制項可以獲得焦點,否則相反。也可以在程式中通過代碼來設定:

v.setFocusable(true/false); 

2、控制按遙控器上下左右時下一個獲得焦點的控制項

    • android:nextFocusUp="@+id/..."  
    • android:nextFocusDown="@+id/..."  
    • android:nextFocusLeft="@+id/..."  
    • android:nextFocusRight="@+id/..." 
    • 以下是通過程式設定
    • v.setNextFocusUp(id); 
    • v.setNextFocusDown(id);
    • v.setNextFocusRight(id);  

v.setNextFocusRight(id); 

3、TV解析度的適配問題

如果適配不對,容易出現OOM(out of memory)問題。按現有TV情況,一般建議設定

drawable-sw1080dp

 drawable-sw720dp

相應地,提供對應解析度下的尺寸: 

    values-sw1080dp

    values-sw720dp

比如同樣的都是1080P,有的是32寸,有的是42寸。尺寸小,dpi高,使得圖片會被壓縮。在values檔案裡,可以使用dp、PIX,預設dpi是160。也可以考慮values採用PX驗證一下。

4、陰影、倒影的程式實現(完全可以由美工實現,這裡代碼只作參考)

倒影原理:基本上就是將原圖倒置,畫在畫布上,然後加上一個半透明的蒙版。

 陰影製作效果:網上有很多講陰影實現的教程,而這裡實現的是在一個圓角矩形的圖片四周加上陰影製作效果。實現辦法是在原圖四邊加上矩形的陰影,然後在四個圓角的地方畫扇形陰影來實現。

  1. /**  
  2.      * @author: sunnybaby 
  3.      * @Title: createShadowBitmap  
  4.      * @Description: 產生帶陰影圖片 
  5.      * @param orignalBitmap:原圖 
  6.      * @param shadowMargin:陰影邊寬 
  7.      * @param iconCornerRadius:原圖圓角半徑 
  8.      * @return :產生的帶陰影圖片 
  9.      */  
  10.     public static Bitmap createShadowBitmap(Bitmap orignalBitmap,  
  11.             int shadowMargin, int iconCornerRadius) {  
  12.         int w = orignalBitmap.getWidth();  
  13.         int h = orignalBitmap.getHeight();  
  14.         Bitmap shadowBitmap = Bitmap.createBitmap(w + shadowMargin * 2, h  
  15.                 + shadowMargin * 2, Config.ARGB_8888);  
  16.         int width = shadowBitmap.getWidth();  
  17.         int height = shadowBitmap.getHeight();  
  18.         Canvas canvas = new Canvas(shadowBitmap);  
  19.         canvas.drawBitmap(orignalBitmap, shadowMargin, shadowMargin, null);  
  20.         Paint paint = new Paint();  
  21.         paint.setXfermode(new PorterDuffXfermode(Mode.DST_OVER));  
  22.         int radius = shadowMargin + iconCornerRadius;  
  23.         // 四個邊的陰影製作效果,採用線性陰影,寬度等於陰影邊距+圓角半徑  
  24.         LinearGradient leftGradient = new LinearGradient(radius, 0, 0, 0,  
  25.                 0x7F000000, 0x00000000, TileMode.CLAMP);  
  26.         LinearGradient rightGradient = new LinearGradient(width - radius, 0,  
  27.                 width, 0, 0x7F000000, 0x00000000, TileMode.CLAMP);  
  28.         LinearGradient topGradient = new LinearGradient(0, radius, 0, 0,  
  29.                 0x7F000000, 0x00000000, TileMode.CLAMP);  
  30.         LinearGradient bottomGradient = new LinearGradient(0, height - radius,  
  31.                 0, height, 0x7F000000, 0x00000000, TileMode.CLAMP);  
  32.         paint.setShader(leftGradient);  
  33.         canvas.drawRect(0, radius, radius, height - radius, paint);  
  34.         paint.setShader(rightGradient);  
  35.         canvas.drawRect(width - radius, radius, width, height - radius, paint);  
  36.         paint.setShader(topGradient);  
  37.         canvas.drawRect(radius, 0, width - radius, radius, paint);  
  38.         paint.setShader(bottomGradient);  
  39.         canvas.drawRect(radius, height - radius, width - radius, height, paint);  
  40.         // 四個角的陰影製作效果,採用圓形陰影,半徑等於陰影邊距+圓角半徑  
  41.         RadialGradient topLeftCornerGradient = new RadialGradient(radius,  
  42.                 radius, radius, 0x7F000000, 0x00000000, TileMode.CLAMP);  
  43.         RadialGradient topRightCornerGradient = new RadialGradient(width  
  44.                 - radius, radius, radius, 0x7F000000, 0x00000000,  
  45.                 TileMode.CLAMP);  
  46.         RadialGradient bottomLeftCornerGradient = new RadialGradient(radius,  
  47.                 height - radius, radius, 0x7F000000, 0x00000000, TileMode.CLAMP);  
  48.         RadialGradient bottomRightCornerGradient = new RadialGradient(width  
  49.                 - radius, height - radius, radius, 0x7F000000, 0x00000000,  
  50.                 TileMode.CLAMP);  
  51.         // 畫四個角,就是畫四個圓心角為90度的扇形,drawArc函數第一個參數為圓弧所在圓的的外接矩形,第二個參數為起始角度,第三個參數為扇形順時針滑過的角度,第四個參數如果為true時,在繪製圓弧時將圓心包括在內(用來畫扇形),第五個參數為畫筆  
  52.         paint.setShader(topLeftCornerGradient);  
  53.         canvas.drawArc(new RectF(0, 0, radius * 2, radius * 2), 180, 90, true,  
  54.                 paint);  
  55.         paint.setShader(topRightCornerGradient);  
  56.         canvas.drawArc(new RectF(width - radius * 2, 0, width, radius * 2),  
  57.                 270, 90, true, paint);  
  58.         paint.setShader(bottomLeftCornerGradient);  
  59.         canvas.drawArc(new RectF(0, height - radius * 2, radius * 2, height),  
  60.                 90, 90, true, paint);  
  61.         paint.setShader(bottomRightCornerGradient);  
  62.         canvas.drawArc(new RectF(width - radius * 2, height - radius * 2,  
  63.                 width, height), 0, 90, true, paint);  
  64.         return shadowBitmap;  
  65.     }  

 

讀《Android電視機(機頂盒)初次開發的一些經驗分享》後的筆記

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.