項目要求: 筆者曾經做過一個項目,其中登入界面的互動令人印象深刻。互動設計師給出了一個非常作的設計,要求做出包含根據情況可變色的下劃線,左側有可變圖示,右側有可變删除标志的輸入框,如圖![]()
Android 如何自定義EditText 下劃線?
</blockquote>
記錄制作過程:
第一版本
<code>public class lineedittext extends edittext {</code>
<code></code>
<code>public lineedittext(context context) {</code>
<code>public lineedittext(context context, attributeset attrs) {</code>
<code>public lineedittext(context context, attributeset attrs, int defstryle) {</code>
/** * 2014/7/31 * * @author aimee.zhang */
// left.setbounds(0, 0, 30, 40); // this.setcompounddrawables(left, null, null, null);
<code>}</code>
效果圖:
代碼解釋:
變量名 <code>status_focused,status_unfocused,status_error</code> 标示了三種狀态,選中狀況為藍色,未選中狀态為灰色,錯誤狀态為紅色。<code>focuseddrawableid unfocuseddrawableid errordrawableid</code>存放三種狀态的圖檔,放置于最左側。
<code>canvas.drawline(0, this.getheight() - 1, this.getwidth(),this.getheight() - 1, mpaint); //畫edittext</code>最下方的線
<code>setcompounddrawableswithintrinsicbounds(left, null, del_btn, null);</code> //放置左邊的和右邊的圖檔(左,上,右,下)
相當于 <code>android:drawableleft="" android:drawableright=""</code>
ontouchevent 當手機點選時,第一個先執行的函數,當點選右側删除圖示是清空 edittext
setstatus 根據不同的狀态,左邊的圖檔不一樣
存在的問題:
這版本雖然基本功能已經實作,但是不符合需求,設計中要求文本框中無文字時,右側删除按鈕不顯示,不點選删除按鈕,删除按鈕要保持灰色,點選時才可以變藍色。
是以有了第二個版本
<code>public class lineedittext extends edittext implements textwatcher, onfocuschangelistener{</code>
// private void setdrawable() { // if (length() < 1) { // setcompounddrawableswithintrinsicbounds(left, null, null, null); // } else { // setcompounddrawableswithintrinsicbounds(left, null, del_btn,null); // } // }
// left.setbounds(0, 0, 30, 40); // this.setcompounddrawables(left, null, null, null); setcompounddrawableswithintrinsicbounds(left,null,null,null); } postinvalidate(); }
比較關鍵的方法是:ontouchevent
當進入界面,點選輸入框,要判斷輸入框中是否已有文字,如果有則顯示灰色的删除按鈕,如果沒有則不顯示,如果點選了删除按鈕,删除按鈕變藍色
這個版本依舊存在問題,就是輸入長度超過輸入框,所畫的線不會延伸,如圖
解決方法:
<code>@override</code>
w:擷取控件長度 x:延伸後的長度
最終效果:
在分享完這個界面的代碼設計後,筆者跟大家唠一些新玩意。話說身處在帝都,如果不利用好帝都的豐厚資源,又如何對得起每天吸入的幾十斤霧霾?
話唠的分享
在帝都生活,我每天早晨起來都會告訴自己,又是新的一天,要認真過。
寫一個 app 很容易,寫好一個 app 很難。如何檢驗自己所寫的 app 的性能狀況,使用者體驗?
什麼是 apm?
in the fields of information technology and systems management, application performance management (apm) is the monitoring and management of performance and availability of software applications. apm strives to detect and diagnose complex application performance problems to maintain an expected level of service. apm is "the translation of it metrics into business meaning .
國内外有已很多成熟的 apm 廠商,筆者也曾染指過幾家,如appdynamics,newrelic,oneapm
還有專注于 app 崩潰監控的産品:crashlytics,crittercism,bugly等
今天我想給大家分享的是從oneapm mobile insight 産品中發現的一塊新大陸--卡頓監控
對流暢度的概念,相信大家并不陌生,即 1s 中之内繪圖重新整理信号中斷的次數。流暢度次數越接近 40 時,使用者能感覺到卡頓,流暢度在 20以下卡頓比較嚴重。oneapmmobile insight的卡頓監控就是一個監控流暢度名額的子產品。
卡頓趨勢圖:随時間的推移,回報卡頓發生次數的趨勢情況
裝置分布圖:卡頓現象集中分布的裝置類型
卡頓頁面:發生卡頓的頁面有哪些,其中平均流暢度是多少,卡頓了多少次等資訊。
檢視單個頁面的卡頓情況,并從頁面線程加載的情況中分析造成卡頓原因
如果你也想檢驗一下自己所寫的 app 的使用者體驗情況,不妨試試這個新玩意~~
oneapm mobile insight 以真實使用者體驗為度量标準進行 crash 分析,監控網絡請求及網絡錯誤,提升使用者留存。通路 oneapm 官方網站感受更多應用性能優化體驗,想閱讀更多技術文章,請通路 oneapm 官方技術部落格。
本文轉自 oneapm 官方部落格