android listview display all available items without scroll with static header

前端 未结 12 652
一生所求
一生所求 2020-12-02 10:12

I\'m having a little difficulties while trying to get a certain layout to work: I want to have list. List does not have to be scrollable, but should be shown completely. But

12条回答
  •  长情又很酷
    2020-12-02 10:41

    I just did it using setting params of ListView

    public static void setListViewHeightBasedOnChildren(ListView listView) {
    
        //this comes from value from xml tag of each item
        final int HEIGHT_LARGE=75;
        final int HEIGHT_LARGE=50;
        final int HEIGHT_LARGE=35;
        ViewGroup.LayoutParams params = listView.getLayoutParams();
    
        int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    
        switch(screenSize) {
    
        case Configuration.SCREENLAYOUT_SIZE_LARGE:
             params.height =(int) (HEIGHT_LARGE*size);
             break;
        case Configuration.SCREENLAYOUT_SIZE_NORMAL:
             params.height =(int) (HEIGHT_NORMAL*size);
             break;
        case Configuration.SCREENLAYOUT_SIZE_SMALL:
              params.height =(int) (HEIGHT_SMALL*size);
              break;
        }
        listView.setLayoutParams(params);  
    }
    

提交回复
热议问题