ScrollView中包含一個GridView ,致使界面默認顯示在ScrollView的底部
java
解決:(1) gridView.setFocusable(false);android
(2) scrollView.smoothScrollTo(0,20);
ide
2. 根據item數量自增高的GridView佈局
public class NoScroolGridView extends GridView { public NoScroolGridView(Context context) { super(context); } public NoScroolGridView(Context context, AttributeSet attrs) { super(context, attrs); } public NoScroolGridView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } //不出現滾動條 @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }
3. 引用自定義控件時 引用自定義屬性
post
增長自定義命名空間 : xmlns:前綴=http://schemas.android.com/apk/res/應用程序包路徑code
4. RecyclerView 佈局管理器採用GridLayoutManager 以後 添加頭部視圖 致使錯位xml
GridLayoutManager有三列,每一個item爲1的話,頭部視圖則佔3
token
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int i) { if (i==0){ return 3; } return 1; } });
5.Activity獲取Fragment裏面的控件內存
getSupportFragmentManager().findFragmentById(R.id.fragment).getView().findViewById(R.id.btn)
6. android中Handler.removeCallbacksAndMessages(null)的做用rem
public final void removeCallbacksAndMessages (Object token) Added in API level 1 Remove any pending posts of callbacks and sent messages whose obj is token. If token is null, all callbacks and messages will be removed.
設置爲Null,會移除全部的Callbacks和Messages,這樣能夠避免內存泄漏