2

is there any standard way in Android for creating a list view covering content by width, but with the height big enough for displaying a fixed number of rows?

For example, I would want my scrollable listview to pop up in the middle of a screen/activity displaying exactly 6 items out of 20 at a time.

  • What if someone is using your app on a large tablet? Do you really want to restrict the user to seeing 6 rows at at time? Sounds rather limiting. – Peri Hartman May 13 '15 at 22:51
  • That should be fine. My items are going to wrap images different per size/density, I don't think it will be too bad. – Sergey Solovyev May 13 '15 at 23:07
  • Well, I don't really have an answer for you. But I think the way to do it is to size your items so 6 of them exactly fill the space allocated for the list. – Peri Hartman May 14 '15 at 01:35

2 Answers2

1

Try this.

adapter.setViewBinder(new SimpleAdapter.ViewBinder() {  
    public boolean setViewValue(View view, Object data, String textRepresentation) {  
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view
                .getLayoutParams();
        params.height = Math.round(mScreenHeight/ 6); 

        return true;  
        }  
    }  
);  
Cbibejs
  • 91
  • 4
  • Sounds like this code stretches each of the views to make 6 of them to fit the full screen? but I don't really want to cover full screen, perhaps I can do something using getView/getCount methods of the ListView adapter. – Sergey Solovyev May 14 '15 at 10:56
1

The solution from wrap_content for a listview's width works ( see getWidestView ). Same thing can be applied for height ( measure a height using fake parent and *6 after )

Community
  • 1
  • 1