ScrollView中包含一个GridView ,导致界面默认显示在ScrollView的底部
解决:(1) gridView.setFocusable(false);
(2) scrollView.smoothScrollTo(0,20);
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. 引用自定义控件时 引用自定义属性
增加自定义命名空间 : xmlns:前缀=http://schemas.android.com/apk/res/应用程序包路径
4. RecyclerView 布局管理器采用GridLayoutManager 之后 添加头部视图 导致错位
GridLayoutManager有三列,每个item为1的话,头部视图则占3
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)的作用
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,这样可以避免内存泄漏