興業(yè)ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!
本文地址: http://blog.csdn.net/caroline_wendy/article/details/21330733
Android允許從已有的視圖工具箱(Widget Tool Box)派生子類(lèi) 或 實(shí)現(xiàn)自己的視圖控件;
通過(guò)重寫(xiě)事件處理程序和onDraw()方法, 但是仍然回調(diào)超類(lèi)(super)的方法, 可以對(duì)視圖進(jìn)行定制, 而不必實(shí)心它的功能;
前置步驟參見(jiàn): http://blog.csdn.net/caroline_wendy/article/details/21246963
步驟:
位置: java->package->ToDoListItemView.java
package mzx.spike.todolist.app; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.TextView; /** * Created by C.L.Wang on 14-3-16. */ public class ToDoListItemView extends TextView{ private Paint marginPaint; private Paint linePaint; private int paperColor; private float margin; public ToDoListItemView (Context context, AttributeSet ats, int ds) { super(context, ats, ds); init(); } public ToDoListItemView (Context context) { super(context); init(); } public ToDoListItemView (Context context, AttributeSet ats) { super(context, ats); init(); } private void init() { //獲得對(duì)資源列表的引用 Resources myResources = getResources(); marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG); marginPaint.setColor(myResources.getColor(R.color.notepad_margin)); linePaint = new Paint(Paint.ANTI_ALIAS_FLAG); linePaint.setColor(myResources.getColor(R.color.notepad_lines)); paperColor = myResources.getColor(R.color.notepad_paper); margin = myResources.getDimension(R.dimen.notepad_margin); } @Override public void onDraw(Canvas canvas) { canvas.drawColor(paperColor); canvas.drawLine(0, 0, 0, getMeasuredHeight(), linePaint); canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), linePaint); canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint); canvas.save(); canvas.translate(margin, 0); super.onDraw(canvas); canvas.restore(); } } 1. 繼承TextView類(lèi), 是文本視圖的定制;
2. 重載構(gòu)造函數(shù), 包含三個(gè)參數(shù)的重載版本,回調(diào)超類(lèi)(super)之后,初始化資源私有變量(init);
3. 在Init()中, 獲得資源列表的引用(getResource), 將資源文件轉(zhuǎn)換為可以調(diào)用的參數(shù)(myResource.getXXX),初始化資源私有變量;
4. 重寫(xiě)(Override)OnDraw方法, 設(shè)置顏色, 畫(huà)線, 指定寫(xiě)入格式;
5. canvas.translate(), 使輸出文件, 后移margin距離;
位置: res->values->colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="notepad_paper">#EEF8E0A0</color> <color name="notepad_lines">#FF0000FF</color> <color name="notepad_margin">#90FF0000</color> <color name="notepad_text">#AA0000FF</color> </resources>
位置: res->values->dimen.xml
<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> <dimen name="notepad_margin">30dp</dimen> </resources>
位置: res->layout->todolist_item.xml
<?xml version="1.0" encoding="utf-8"?> <mzx.spike.todolist.app.ToDoListItemView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:scrollbars="vertical" android:textColor="@color/notepad_text" android:fadingEdge="vertical" />
1. 標(biāo)簽為類(lèi)名, 即ToDoListItemView類(lèi), 重載了TextView的方法;
2. 設(shè)置相應(yīng)的屬性標(biāo)簽;
位置: java->package->ToDoListActivity
...... int resID = R.layout.todolist_item; //三個(gè)參數(shù) aa = new ArrayAdapter<String>(this, resID, toDoItems); toDoListFragment.setListAdapter(aa); ......
找到資源文件的ID, 傳入適配器;
代碼下載: http://download.csdn.net/detail/u012515223/7050371
分享文章:Android-ToDoList(定制樣式)詳解
文章鏈接:http://chinadenli.net/article18/jpsidp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、App開(kāi)發(fā)、網(wǎng)站策劃、企業(yè)網(wǎng)站制作、網(wǎng)站內(nèi)鏈、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)