Arvin_ghost 2015-09-13 08:43 采纳率: 0%
浏览 1490

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>

求帮助。。。。。

  • 写回答

4条回答 默认 最新

  • 91program 博客专家认证 2015-09-13 09:10
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器