android这样的一个自定义View有什么问题吗?

不知道为什么在布局中添加了却没有什么显示:
//界面更新
BookButton bookButton=new BookButton(SelectAty.this,newNote);
layout.addView(bookButton);

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){
        //没有效果?
        setMeasuredDimension(150+note.getPagesNumber(),1000);
    }

    public void setNoteName(String noteName){
        note.setNoteName(noteName);
        //更改textView,完成界面的更新
        this.noteName.setText(noteName);
    }

    public Note getNote(){
        return note;
    }

}

book_button.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/book1"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/noteName"
        android:layout_centerInParent="true"
        android:layout_width="15dp"
        android:layout_height="50dp" />
</RelativeLayout>

求帮助。。。。。

setMeasuredDimension(150+note.getPagesNumber(),1000);
这一行没有作用的话,请看看其中的参数是否合法?另外,看看有没有返回值?如果有,获取一下看看。

不行,构造函数要有一个带attribute的
public BookButton(Context context, AttributeSet attrs)

参数对了,然后设置一下宽高,可能你的布局挡住了

应该是没有设置宽高的原因,设置layoutparams,为其添加宽高试试