1.ToolBar
參看該文章http://www.itdecent.cn/p/79604c3ddcae
項(xiàng)目參看: SystemUITest
2.RecyclerView
http://www.itdecent.cn/p/f592f3715ae2
- Android中的自定義屬性
http://blog.csdn.net/lmj623565791/article/details/45022631
其中有點(diǎn)問題的是:就我寫的例子而言
關(guān)于引用自定義控件的命名空間,是放在自定義控件下的(沒問題),而不是放在布局根節(jié)點(diǎn)下的。代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.systemuitest.AttrsTypedArray.CustomView
//放在這個(gè)地方?jīng)]有問題
xmlns:xyz="http://schemas.android.com/apk/res/com.example.systemuitest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xyz:text="hello"
xyz:textAttr="29"
/>
</LinearLayout>
關(guān)于命名空間參考:http://blog.csdn.net/janice0529/article/details/34425549
TypedArray是(存放attrs列出的屬性值)方便直接取出
public class CustomView extends View {
private static final String TAG=CustomView.class.getSimpleName();
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
//Return a TypedArray holding the attribute values in set that are listed in attrs.
//返回一個(gè)TypedArray(存放attrs列出的屬性值)
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.test);
String text = ta.getString(R.styleable.test_text);//別忘了是放在styleable之下的
int textAttr = ta.getInteger(R.styleable.test_textAttr, -1);
Log.e(TAG, text+"----"+textAttr );
ta.recycle();
}
}
關(guān)于第一篇博文中用數(shù)組存儲(chǔ)attr的屬性值,并用TypedArray通過下標(biāo)獲取對應(yīng)的屬性值
會(huì)出現(xiàn)一個(gè)bug:
Error: Expected resource of type styleable
解決方法如下:在使用 TypedArray 的方法處
加上 @SuppressWarnings("ResourceType")
@SuppressWarnings("ResourceType")
案例代碼
//在這兒加的
@SuppressWarnings("ResourceType")
public class CustomVewActivity extends View {
private static final String TAG = CustomVewActivity.class.getSimpleName();
private static final int[] mAttrs = {R.attr.test3, R.attr.test4};
public CustomVewActivity(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray ta = context.obtainStyledAttributes(attrs, mAttrs);
String test3 = ta.getString(0);
int test4 = ta.getInteger(1, -1);
Log.e(TAG, test3+"--"+test4 );
ta.recycle();
}
}
- 加入分割線
參看:http://www.itdecent.cn/p/4eff036360da
和鴻洋大神的http://blog.csdn.net/lmj623565791/article/details/45059587
getItemOffsets():從字面意思就是Item要偏移, 由于我們在Item和Item之間加入了分隔線,線其實(shí)本質(zhì)就是一個(gè)長方形,也是用戶自定義的,既然線也有長寬高,就畫橫線來說,上面的Item加入了分隔線,那下面的Item就要往下平移,平移的量就是分隔線的高度。
- 關(guān)于分割線后續(xù)實(shí)際代碼
上面兩篇已經(jīng)講得很清楚了,原理就是第一篇博文寫的那樣,很清晰明白,需要注意的問題是在列表方向是垂直的時(shí)候(一般為默認(rèn)),需要畫水平線,第一篇博文思路很清晰,問題在于列表方向是垂直的時(shí)候,item應(yīng)該向下平移
3. DrawingCache

關(guān)于這段代碼其中用到DrawingCache,官網(wǎng)API解釋:
void setDrawingCacheEnabled (boolean enabled)
Enables or disables the drawing cache. When the drawing cache is enabled, the next call to getDrawingCache() or buildDrawingCache() will draw the view in a bitmap. Calling [draw(android.graphics.Canvas)]
will not draw from the cache when the cache is enabled. To benefit from the cache, you must request the drawing cache by calling getDrawingCache()
and draw it on screen if the returned bitmap is not null.
關(guān)于參數(shù):
boolean enabled: true to enable the drawing cache, false otherwise
若想更新cache, 必須要調(diào)用destoryDrawingCache方法把舊的cache銷毀,才能建立新的。
>當(dāng)調(diào)用setDrawingCacheEnabled方法設(shè)置為false, 系統(tǒng)也會(huì)自動(dòng)把原來的cache銷毀。
對比看
http://souly.cn/%E6%8A%80%E6%9C%AF%E5%8D%9A%E6%96%87/2016/01/05/DrawingCache%E8%A7%A3%E6%9E%90/
有點(diǎn)不同暫時(shí)先記錄吧
4.ObjectAnimation
關(guān)于這部分之前已經(jīng)接觸過而且比較簡單,只是實(shí)現(xiàn)一下動(dòng)畫的類型直接參看下面一篇文章即可
http://blog.csdn.net/dingfengnupt88/article/details/51556597
透明度(alpha)

代碼實(shí)現(xiàn)如上:該示例代碼并沒有在onAnimationEnd中實(shí)現(xiàn)相應(yīng)函數(shù)
5.ViewStub
1.用途:
最大的用途就是實(shí)現(xiàn)View的延遲加載,在需要使用的時(shí)候再加載view
在這個(gè)項(xiàng)目中作者是用來顯示網(wǎng)絡(luò)通知的(平時(shí)不需要顯示,在無網(wǎng)絡(luò)時(shí)使view可見)
2.特點(diǎn)
ViewStub inflate之后就會(huì)變成空的(所以點(diǎn)擊第一次按鈕textView會(huì)顯示出來,第二次點(diǎn)擊會(huì)報(bào)空指針異常 最好加一個(gè)非空判斷)
StubActivity實(shí)現(xiàn).png
