不知道为什么在布局中添加了却没有什么显示:
//界面更新
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);
这一行没有作用的话,请看看其中的参数是否合法?另外,看看有没有返回值?如果有,获取一下看看。