?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未使用自定義屬時(shí) 滴調(diào)用 AttributeSet 兩個(gè)參數(shù)??// onMeasuer 決定內(nèi)部View(子view)的寬和高 ,以及自己的寬和高??// onLayout 決定子控件的位置??WindowManager wm = (WindowManager) context????.getSystemService(Context.WINDOW_SERVICE);??DisplayMetrics outMetrics = new DisplayMetrics();??wm.getDefaultDisplay().getMetrics(outMetrics);??mScollWith = outMetrics.widthPixels;??// 五十dp轉(zhuǎn)化為 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 關(guān)注
- 1108 瀏覽
添加回答
舉報(bào)
0/150
提交
取消