質問

リストビューの外観をエミュレートするために、垂直リニアレイアウトのエントリ間で仕切りを追加しようとしています。 (この特定の状況では、ListViewを使用することはできません。)

これは私がlist_divider.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_widthの定義とfill_parentオプションを使用してみました。違いはありません。

それを現れないようにする平凡な古いビューについて特別な何かがありますか?

役に立ちましたか?

解決

私は最終的に、フレームレイアウトの中にディバイダービューを包むことでそれを回避しました。コンテンツのない単一の空のビューを持つことは機能しないようです。

<?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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top