亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

仿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 關注
  • 1112 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號