Kris B
Kris B

Reputation: 3578

Adding padding to bottom of ListView

I have a ListView that is being populated with a custom adapter. I'd like to add padding to the last item in the list, to accommodate ads, so the ads do not cover the last item when you scroll to the bottom. The only layout I have is the layout for each row of the ListView:

<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/BaseStyle"
android:orientation="vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
  >  

 <TextView  
    android:id="@+id/text"
    style="@style/BaseStyle.Title"
/>

 </RelativeLayout>

Other than that I just have my custom adapter code that is populating the ListView. Not sure if I need to include any other code to help with the question.

Edit, I don't have a main layout, this is how I'm populating my ListView:

 public class Main extends ListActivity {
 private CustomAdapter adapter;
 private String[] items = {};

 @Override     
 public void onCreate(Bundle icicle) {
      super.onCreate(icicle);

      adapter = new CustomAdapter();

      items = PopulateItems();

      for (String item : items)
           adapter.addItem(item);

      this.setListAdapter(adapter);
      adapter.notifyDataSetChanged();
 }

 private class CustomAdapter extends BaseAdapter {
 private String[] mData;
 private LayoutInflater mInflater;

 public CustomAdapter() {
      mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 }

 public void addItem(String item) {
      mData.add(item);
 }

 @Override
 public int getCount() {
      return mData.size();
 }

 @Override
 public Object getItem(int position) {
      return mData.get(position);
 }

 @Override
 public long getItemId(int position) {
      return position;
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent)
 {
      ViewHolder holder;
      String item = (String)this.getItem(position);

      if (convertView == null)
      {         
           holder = new ViewHolder();

           convertView = mInflater.inflate(R.layout.main, parent, false);
           holder.text = (TextView)convertView.findViewById(R.id.text);
           convertView.setTag(holder);
      } else {
           holder = (ViewHolder)convertView.getTag();
      }
      TextView tvText = holder.text;
      tvText.setText(item);
 }

 static class ViewHolder {
      TextView text;
 }

Upvotes: 0

Views: 1545

Answers (2)

Elodie E2
Elodie E2

Reputation: 580

I think what you are looking for is the "clipToPadding" attribute or the setClipToPadding() method:

<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/your_bottom_padding"/>

Upvotes: 3

user994886
user994886

Reputation: 444

For your needs you need to have another layout file with two views - ListView and a view for the ads. Make sure to use id "@android:id/list" for listview.

Upvotes: 1

Related Questions