Set ListView item height

后端 未结 4 752
闹比i
闹比i 2020-12-13 14:53

this should be a very easy thing to do, but it looks like it\'s very tricky. In my code I have this ListView:



        
4条回答
  •  一整个雨季
    2020-12-13 15:43

    How are you inflating the view?

    If you are setting 'parent' parameter to null like below, then layout parameters are ignored.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ...
      View v = inflater.inflate(R.layout.filtered_trip_row, null);
      …
    
      return v;
    }
    

    Passing 'parent' to inflate should work as you expect.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      ...
      View v = inflater.inflate(R.layout.filtered_trip_row, parent);
      …
    
      return v;
    }
    

    This explains it in detail: Why does LayoutInflater ignore the layout_width and layout_height layout parameters I've specified?

    To avoid getting UnsupportedOperationException, you can add false as an input parameter to the inflator. Example:

    inflater.inflate(R.layout.filtered_trip_row, parent, false)
    

提交回复
热议问题