Adding bottom margin to ListView last element

前端 未结 7 1444
夕颜
夕颜 2021-01-30 06:35

I need to add to add ListView with complicated items background: different for even/odd and rounded corners at the top and bottom. It looks like this:

相关标签:
7条回答
  • 2021-01-30 06:39

    I guess you want to add margin only to last item:

    So you can do in this manner, in your getview method the index of the list item and check if its the last item, then progrmatically add margin to the view.

    0 讨论(0)
  • 2021-01-30 06:42

    add an empty footer in your list like this:

    TextView empty = new TextView(this);
    empty.setHeight(150);
    listview.addFooterView(empty);
    
    0 讨论(0)
  • 2021-01-30 06:46

    you can also do it from code if you want, for example here I react to to EditText different situations:

       if(s.toString().length()>0)
       {
          contacts_lv.setClipToPadding(false);
          contacts_lv.setPadding(0,0,0,270*screenDensity);
       }
       else
       {
          contacts_lv.setClipToPadding(true);
          contacts_lv.setPadding(0,0,0,0);
       }
    
    0 讨论(0)
  • 2021-01-30 06:52

    Add these two lines in your listView XML code:

    android:transcriptMode="alwaysScroll"  
    android:stackFromBottom="true"
    
    0 讨论(0)
  • 2021-01-30 06:57

    Clocksmith's answer is the best and pretty clever. You can also create an empty footer view.

    0 讨论(0)
  • 2021-01-30 06:59

    In your ListView, set a paddingBottom and clipToPadding="false".

      <ListView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingBottom="8dp"
          android:clipToPadding="false"
          android:scrollbarStyle="outsideOverlay"/>
    
    • This also works for RecyclerView.

    • Only use android:scrollbarStyle="outsideOverlay" if you want the scroll bar to not overflow into the padded area.

    0 讨论(0)
提交回复
热议问题