0

While this question may sound like a dupe of some others, the fact I am trying to do this in a widget significantly limits my ability to use the proposed solutions elsewhere.

Summarized: I would like to add spacing above the top-most item in the list and below the bottom-most item in order to offset them away from the title bar and bottom bar edge.

Essentially, I am trying to solve the same problem as Add margin above top ListView item (and below last) in Android, however, I cannot rely on having a reference to my ListView object in order to setHeader() or anything like that.

Is this really impossible to do in an Android widget?

Community
  • 1
  • 1
RealCasually
  • 3,593
  • 3
  • 27
  • 34

3 Answers3

0

I assume you are using an adapter for your ListView, so you are inflating additional listview layout. In a getView method, according to list item position (0 and last), place your bottom or top padding.

van
  • 178
  • 5
0

So ,here i have override function of adapter.From this function you can change or specify margin,height.Here you need to take object of Layout which you are using and from this you can change layout attributes.

 @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                LayoutInflater mInflater = (LayoutInflater) context
                        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
                convertView = mInflater.inflate(R.layout.drawer_list_item, null);
            }
            if (position == 0) {//for first row



                ImageView imgIcon = (ImageView) convertView.findViewById(R.id.icon);
                TextView txtTitle = (TextView) convertView.findViewById(R.id.title);

                RelativeLayout.LayoutParams relate = new RelativeLayout.LayoutParams(200, 200);
                relate.setMargins(150, 0, 0, 0);

                imgIcon.setLayoutParams(relate);
                RelativeLayout.LayoutParams text = new RelativeLayout.LayoutParams(300, 100);
                text.setMargins(150, 180, 0, 0);


                }
    return convertView ;

//HOPE IT HELP

-1

in the adapter during getView() check if it's either position 0 or .getLength() and set LayoutParams on the convertView there

chris-tulip
  • 1,840
  • 1
  • 15
  • 22