Android扩展线性布局和膨胀

时间:2012-09-05 20:59:06

标签: android android-layout android-inflate

我正在扩展一个包含2个TextView的线性布局。 TextViews是从我创建的模板布局中膨胀的。 我的问题是我设置的背景是覆盖整个原始,而只是包含文本的部分。但是,当我以动态的方式设置相同的布局时,它的工作和裁剪都很好。

        final LayoutInflater inflater = LayoutInflater.from(this.getContext());

    //The title.
    title = (TextView)inflater.inflate(R.layout.text_view_day_title, null);
    title.setText("bla bla");

    //The info.
    info = (TextView)inflater.inflate(R.layout.text_view_day_info, null);
    info.setText("bla bla 2");

    this.addView(title);
    this.addView(info);

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

  • 在xml和addview中创建一个线性布局。
  • 确保膨胀的xml没有背景背景,并且它们之间有边距以显示主xml布局的背景。
相关问题