为了账号安全,请及时绑定邮箱和手机立即绑定

仿QQ5.0的自定菜单,在子控件报空指针异常,子类控件不能获取,mWapper = (LinearLayout) getChildAt(0)

仿QQ5.0的自定菜单,在子控件报空指针异常,子类控件不能获取,mWapper = (LinearLayout) getChildAt(0)

寒虞羲墨逸 2016-02-16 00:04:57
 public class SlidingMenu extends HorizontalScrollView { private LinearLayout mWapper; private ViewGroup mMenu; private ViewGroup mContent; private int mScollWith; // dp private int mMenuRighPadding = 50; private Boolean once; private int mMenuWidth; public SlidingMenu(Context context, AttributeSet attrs) {  super(context, attrs);  // TODO Auto-generated constructor stub未使用自定义属时 滴调用 AttributeSet 两个参数  // onMeasuer 决定内部View(子view)的宽和高 ,以及自己的宽和高  // onLayout 决定子控件的位置  WindowManager wm = (WindowManager) context    .getSystemService(Context.WINDOW_SERVICE);  DisplayMetrics outMetrics = new DisplayMetrics();  wm.getDefaultDisplay().getMetrics(outMetrics);  mScollWith = outMetrics.widthPixels;  // 五十dp转化为 sp  mMenuRighPadding = (int) TypedValue.applyDimension(    TypedValue.COMPLEX_UNIT_DIP, 50, context.getResources()      .getDisplayMetrics()); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  // TODO Auto-generated method stub  if (!once) {   mWapper = (LinearLayout) getChildAt(0);   mMenu = (ViewGroup) mWapper.getChildAt(0);   mContent = (ViewGroup) mWapper.getChildAt(1);      mMenuWidth = mMenu.getLayoutParams().width = mScollWith     - mMenuRighPadding;   mContent.getLayoutParams().width = mScollWith;   once = true;  }  super.onMeasure(widthMeasureSpec, heightMeasureSpec); }
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1076 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信