就是一个简单的自定义view,想要通过传入一个简单的自定义类,根据这个类的大小自确定view自己的大小,可是不重写onMeasure的时候还会显示出来,重写了就什么都没有了,但是点击位置还是会触发这个自定义view的事件
这是重写的方法
// view的大小由note的大小决定
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
//没有效果?
// super.onMeasure(widthMeasureSpec,heightMeasureSpec);
setMeasuredDimension(1000+note.getPagesNumber(),10000);
}
自定义view完整码:
public class BookButton extends RelativeLayout {
Note note;
TextView noteName;
public BookButton(Context context,Note note){
super(context);
this.note=note;
LayoutInflater.from(context).inflate(R.layout.book_button,this);
noteName=(TextView)findViewById(R.id.noteName);
noteName.setText(note.getNoteName());
}
// view的大小由note的大小决定
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
//没有效果?
// super.onMeasure(widthMeasureSpec,heightMeasureSpec);
setMeasuredDimension(1000+note.getPagesNumber(),10000);
}
}
这个view都是在java代码中new出来的,可是什么都没有。。。。。