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,这样能够避免内存泄漏