Friday, May 29, 2015

Screen Density 簡介

screen density, 是Android為了支援多屏螢幕所提出的提出的概念, 簡單來說, 描述的就是一定區域(螢幕)範圍內, 有多少個相素(pixel), 單位則是dip (dots per inch).

screen density 劃分為幾種等級, low(ldip), medium(mdip), high(hdip), extra-high(xhdip), extra-extra-high(xxhdip), extra-extra-extra-high(xxxhdip), 

其中並以medium為基礎, 對應的倍數描述如下

low (0.75) , medium(1.0), high(1.5), extra-high(2.0), extra-extra-high(3.0) , extra-extra-extra-high(4.0)

以medium為例, 每單位面積有1個pixel, 而low 則是每單位面積僅有0.75個pixel
可以了解到, 當screen density愈高, 也就是解析度愈高的意思

參考資料

Monday, May 4, 2015

WebView簡介(二) - loadUrl , loadData, loadDataWithBaseUrl

之前已經介紹過loadUrl的使用方式, 接下來繼續介紹WebView提供的其他載入內容的方法
  • loadData
    • Input : 
      • data, string , 將以WebView載入的內容
      • mineType, string, 內容資料格式, 若設定為null則以預設值"text/html"表示
      • encoding, string, 內容編碼方式,
    • 使用方式
      WebView webView = new WebView(getBaseContext());
      webView.loadData("<html><body><h1> Hello World!!</h1> </body></html>","text/html","UTF-8");
    • 範例結果
  • loadDataWithBaseUrl
    • Input : 
      • baseUrl ,string , 所設定的基礎位置, 可設定為各種schema, 包含file, http, https, ftp, etc..,若設定為null時則以預設值'about:blank'表示
      • data, string , 將以WebView載入的內容
      • mineType, string , 內容資料格式, 若設定為null則以預設值"text/html"表示
      • encoding, string , 內容編碼方式
      • historyUrl, string, 用以表示WebView的history, 若設定為null,則以'about:blank'表示
    • 使用方式
      WebView webView = new WebView(getBaseContext());
      webView.loadData("<html><body><img src='mipmap/ic_launcher.png'/></body></html>","text/html","UTF-8");
    • 範例結果
  • 結論
    • loadDataWithBaseUrl當然在使用上屬於較為複雜的方式, 但根據baseUrl不同, 則可以使用asset, res資料夾當中的資源, 相當的好用

※參考資料

Wednesday, April 29, 2015

WebView簡介(一)

簡單來說, WebView是用來顯示網頁頁面的元件

接下來介紹如何使用WebView

首先當然是先建立一個Android的Project, 以Android Studio為例子

並在完成相關設定後,可以看到畫面如下

既然主要用來顯示網頁頁面, 當然要先加入可以連接網路的權限也就是android.permission.INTERNET


開始使用webview的原件

WebView webView = new WebView(getBaseContext());
webView.loadUrl("http://http://developer.android.com/reference/android/webkit/WebView.html");


執行之後就可以看到應用程式上看到網頁資料啦

※參考資料