2016-12-27 34 views
0

scrollviewまたはnestedscrollビュー内でlistviewを実装しようとしていますが、リストの最後の項目が正しく表示されません。リストビューがスクロール表示で正しく表示されない

私を助けてください。どのように見えるのすべての項目を適切

ここに私のコード

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 


      <TextView 
       android:id="@+id/electronic_TV" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:text="@string/no_data_find" 
       android:textSize="40dp" 
       android:textStyle="bold" 
       android:visibility="gone" /> 

      <RelativeLayout 
       android:id="@+id/rltop" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="15dp" 
       android:layout_marginTop="10dp" 
       android:background="@color/white"> 

       <TextView 
        android:id="@+id/tvadver" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:text="ADVERTISEMENT" 
        android:textColor="@color/light_grey" 
        android:textSize="12dp" 
        android:textStyle="normal" /> 

       <RelativeLayout 
        android:id="@+id/rl_viewfliper" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/tvadver" 
        android:layout_marginBottom="10dp" 
        android:layout_marginLeft="1dp" 
        android:layout_marginRight="10dp"> 

        <ViewFlipper 
         android:id="@+id/view_flipper" 
         android:layout_width="fill_parent" 
         android:layout_height="130dp"> 

        </ViewFlipper> 
       </RelativeLayout> 
      </RelativeLayout> 

      <ListView 
       android:id="@+id/fashionLV" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/tvmsg" 
       android:layout_weight="1" 
       android:divider="@android:color/transparent"></ListView> 


     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
</LinearLayout> 

Javaコード

commanAdapter = new CommanAdapter(getActivity(), commanModelArrayList); 
          fashionLV.setAdapter(commanAdapter); 
          GeneralFunction.setListViewHeightBasedOnChildren(fashionLV); 

GeneralFunctionコードです:

public static void setListViewHeightBasedOnChildren(ListView listView) { 
     ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); 
     if (listAdapter == null) { 
      // pre-condition 
      return; 
     } 

     int totalHeight = 0; 
     for (int i = 0; i < listAdapter.getCount(); i++) { 
      View listItem = listAdapter.getView(i, null, listView); 
      listItem.measure(0, 0); 
      totalHeight += listItem.getMeasuredHeight(); 
     } 

     ViewGroup.LayoutParams params = listView.getLayoutParams(); 
     params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
     listView.setLayoutParams(params); 

    } 
+1

litsview – Shane

+0

に下マージン== 15dpを追加すると、マージンボトムを最後に追加しても表示されません。リストビューは下からの間隔を保ちます – ajit

+0

あなたはリストビューまたはその行にカスタム高さを指定しましたか? – Shane

答えて

0

"リストビュー" と "ScrollView" の使用は、一緒にオブジェクトをお勧めしません。

同じアダプタで異なるビューを使用する必要があります。例えば;

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     View rowView = convertView; 
     MyListItem currentItem = myList.get(position); 
     LayoutInflater Inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     if (currentItem.getListItemType() == "Description") { 
       rowView = Inflater.inflate(R.layout.descriptionlayout, null); 
       TextView tvDesc= (TextView) rowView.findViewById(R.id.tvAccountType); 
       tvDesc.setText("Desc"); 
     } else if (currentAccountItem.getListItemType() == "ListItem") { 
       rowView = Inflater.inflate(R.layout.list_item_layout, null); 
       ... 
     } 
    } 

リストオブジェクトタイプに「ListItemType」プロパティを追加する必要があります。 getView()メソッドでこのプロパティをチェックし、異なるレイアウトを膨張させます。 あなたの場合、LinearLayoutの新しいレイアウトを作成できます。この行のオブジェクトをリストに挿入します。 ListItemTypeを設定します。このプロパティを確認し、getView()にこのレイアウトを展開します。

希望します。 NestedScrollView内部

0

ListViewは、多くの問題とListViewを作成がRecyclerViewのために行く代わりに使用することは推奨されません、それに応じてアダプタを変更する必要があります。

0

フッタービューをlistviewに追加するには、リストビュー方式を使用します。

listViewの要素がすべて表示されます。

関連する問題