码迷,mamicode.com
首页 > 其他好文 > 详细

自定义基础回顾

时间:2017-11-04 16:35:14      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ams   view   protected   raw   menu   you   prot   mos   bool   

1.@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measureSpec = MeasureSpec.makeMeasureSpec(menuWidth, MeasureSpec.EXACTLY);
//测量所有子view的宽高
//通过getLayoutParams方法可以获取到布局文件中指定宽高
menuView.measure(measureSpec, heightMeasureSpec);
//直接使用SlideMenu的测量参数,因为它的宽高都是充满父窗体
mainView.measure(widthMeasureSpec, heightMeasureSpec);

  -offsetTopAndButton();  offsetLeftRight()//测量宽度

  -Measure.makeMeasureSpec();// MeasureSpec.EXACTLY 相当于 MATCH_PARENT,AT_MOST相当于WARP_CONTENT,UNSPECIFIED 控件的大小

  -setMeasuredDimension(width, height); 这个方法是把宽度设置上去否则无效

      一般有我们要继承FrameLayout..(继承过ViewGrid的控件),就不需要我们自己写onMeasure();

  

2./**
* l: 当前子view的左边在父view的坐标系中的x坐标
* t: 当前子view的顶边在父view的坐标系中的y坐标
*/
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
Log.e("MAIN", "L: "+l+" t: "+t +" r: "+r + " b: "+b);
menuView.layout(-menuWidth, 0, 0, menuView.getMeasuredHeight());
mainView.layout(0, 0, r, b);
}

  -layout(change left,top,right,button)//摆放view的方法

3 onDrawa()

  -invalidate();重新绘制

 

 

4 onTouchEvent()

  -ACTION_DOWN 

  -ACTION_MOVE

  -ACTION_UP  //计算手指移动的变化

  -scrollTo()  scrolBy()

  

 

自定义基础回顾

标签:ams   view   protected   raw   menu   you   prot   mos   bool   

原文地址:http://www.cnblogs.com/dubo-/p/7783401.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!