2017-05-18 23 views
1

私はリストビュー項目の項目XMLを作成しましたが、リスト項目の上部とリスト項目の下部に2つのビューが作成されていると仮定しました。 これは私のXMLファイルです:なぜ表示行がitem.xmlに表示されないのですか

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/rlo" 
    android:layout_width="match_parent" 
    android:layout_height="40dp" 
    android:orientation="vertical"> 

    <View 
     android:id="@+id/line1" 
     android:layout_width="fill_parent" 
     android:layout_height="1dp" 
     android:layout_alignParentTop="true" 
     android:background="#737373" /> 

    <TextView 
     android:id="@+id/username62" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="yassin elhadedy" 
     android:textSize="15dp" 
     android:textStyle="bold" /> 

    <View 
     android:id="@+id/line2" 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/username62" 
     android:layout_marginTop="21dp" 
     android:background="#737373" /> 
</RelativeLayout> 

と、それは次のように示しています。プロジェクトの実行中に、ID /ラインと

enter image description here

この行は表示されません。 このケースでは何ができますか?

+0

recyclerViewまたはListViewを使用していますか? – Alok

+0

@AlokはlistViewを使用しています – AndyZOny

答えて

1

こんにちはあなたはRecyclerViewを使用している場合、あなたはこのコード

DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), 
      mLayoutManager.getOrientation()); 
    recyclerView.addItemDecoration(mDividerItemDecoration); 

を使用することができるアイテム行分周器を追加するためのよりも、標準のAPIを経由して、これを実現することができますし、あなたは、単にコードの下に使用することができますよりも、リストビューを使用している場合、

<ListView 
    android:id="@+id/ListView01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:divider="@color/redBackground" 
    android:dividerHeight="1dip"> 
</ListView> 
+0

ありがとうalot @ Alok – AndyZOny

+0

が大変助かりますが、申し訳ありません@Alok DividerItemDecorationを解決するにはどうすればよいですか? – AndyZOny

+0

詳細については、このリンクを使用してくださいhttps://developer.android.com/reference/android/support/v7/widget/DividerItemDecoration.htmlおよびhttp://stackoverflow.com/questions/31242812/how-can-a-dividerアンドロイドリサイクルビューで追加されるラインナップ – Alok

関連する問題