zoukankan      html  css  js  c++  java
  • Android ListView动态设置高度

     public void getData() {
            List<TravelPeopleEntity> dataList = new ArrayList<>();
            for (int i = 1; i < 5; i++) {
                TravelPeopleEntity entity = new TravelPeopleEntity();
                entity.setId(i);
                entity.setName("李娜娜");
                entity.setCard("610402199206054213");
                entity.setPhoneNumber("15319079845");
                dataList.add(entity);
            }
            adapter = new TravelPeopleAdapter(this);
            adapter.setData(dataList);
            listView.setAdapter(adapter);
            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = getHeight()
                    + (listView.getDividerHeight() * (adapter.getCount() - 1));
            ((ViewGroup.MarginLayoutParams) params).setMargins(0, 0, 0, 30);
            listView.setLayoutParams(params);
        }
        public int getHeight() {
            int total = 0;
            for (int i = 0; i < adapter.getCount(); i++) {
                View listItem = adapter.getView(i, null, listView);
                listItem.measure(0, 0);
                total += listItem.getMeasuredHeight();
            }
            return total;
        }
  • 相关阅读:
    POJ1045 Bode Plot
    POJ1044 Date bugs
    POJ1043 What's In A Name?
    POJ1042 Gone Fishing
    POJ1041 John's trip
    POJ1040 Transportation
    POJ1039 Pipe
    background-size属性
    一些CSS的备忘
    only-child选择器
  • 原文地址:https://www.cnblogs.com/xiaoyao095/p/5944744.html
Copyright © 2011-2022 走看看