【问题标题】:android: adding horizontal line to layout makes it emptyandroid:在布局中添加水平线使其为空
【发布时间】:2011-06-22 00:21:58
【问题描述】:

将它添加到我的布局后,我将它膨胀并添加到另一个视图后会返回一个空布局

  <View 
  android:layout_width="fill_parent"
  android:layout_height="1px" 
  android:background="#e0e0e0"/>

我是这样充气的

LayoutInflater vi = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View v = vi.inflate(R.layout.stoplistitem, null);
if(dt != null && stop.getDescription() != null)
    dt.setText(stop.getDescription());
if(st != null && stop.getStreet() != null)
    st.setText(stop.getStreet());
if(mt != null && stop.getMunicipal() != null)
    mt.setText(stop.getMunicipal());
if(idt != null && stop.getId() != null){
    idt.setText(stop.getId().toString());

//edit 可以看到视图,但是没有内容

【问题讨论】:

  • 您发布的代码仍然不足以理解您如何将行视频添加到主布局。
  • 它只是在根 LinearLayout 后跟 4 个 EditTexts

标签: android layout view border rulers


【解决方案1】:

通过使用inflate(int resource, ViewGroup root, boolean attachToRoot) 和attachToRoot = true,在膨胀时将此视图附加到ViewGroup,root 是您要在其上膨胀的组件

【讨论】:

  • 所以根必须是我想把我的新视图放在正确的视图?
猜你喜欢
  • 2015-08-11
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
  • 2020-10-14
  • 1970-01-01
  • 2021-01-28
  • 1970-01-01
  • 2019-05-10
相关资源
最近更新 更多