代码之家  ›  专栏  ›  技术社区  ›  Graham Borland

Android视图为空

  •  1
  • Graham Borland  · 技术社区  · 14 年前

    我试图在垂直线性布局中的条目之间添加分隔符,以模拟ListView的外观。(在这种特殊情况下,我不能只使用ListView。)

    这就是我的清单_分隔符.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <View
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:background="@color/panel_border"
      android:layout_width="fill_parent"
      android:layout_height="@dimen/border_width"
     />
    

    下面是一个代码,它试图在每个元素之前膨胀这个分隔符,除了列表中的第一个元素:

    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = 0; i < categories.size(); i++ ) {
    
        if (i > 0)
            items.addView(vi.inflate(R.layout.list_divider, null));    
            // these dividers never appear
    
        // but these main entries always appear just fine    
        items.addView(ad.getView(i, null, null));
    }
    

    主列表项显示正确,但分隔符不可见。

    分频器

    <?xml version="1.0" encoding="utf-8"?>
    <TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:background="@color/panel_border"
      android:layout_width="fill_parent"
      android:layout_height="@dimen/border_width"
      android:text="---"
     />
    

    我尝试过为宽度和高度设置显式像素值,以及使用border\u width definition和fill\u parent选项。这没什么区别。

    一个平淡的老景色有什么特别之处使它不显得那么明显吗?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Graham Borland    14 年前

    我最终通过在FrameLayout中包装分隔器视图来解决这个问题。似乎只有一个没有内容的空视图是行不通的。

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
    
      <View
        android:background="@color/panel_border"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/border_width" />
    
    </FrameLayout>