比较LINEARLAYOUT和RELATIVELAYOUT在LISTVIEW中的内存耗用

来源:互联网 发布:餐饮软件安装 编辑:程序博客网 时间:2024/04/30 01:28

 图片见:http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

 

在LINEARLAYOUT布局里,多用了一个LINEARLAYOUT,造成每一个VIEW建立时都用多

创建一个,资源浪费

The layout pass can be especially expensive when you nest several LinearLayout that use the weight parameter, which requires the child to be measured twice.

 

 

有一点区别是,用LinearLayout,当TITLE下的DESC为空时,the application would simply set the visibility of the second TextView to GONE

 

但是,当用RELATIVE时,如果用DESC来定位TITLE,如果显示不正常

用这个参数 alignWithParentIfMissing

 

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SimpleAdapter ad = new SimpleAdapter(this,list,R.layout.relative,new String[]{"title","desc"}
        ,new int[]{R.id.title,R.id.desc}
        );
        this.setListAdapter(ad);
    }

 private static String[] title = new String[]{"A","B","C","D"
        };
    private static String[] desc = new String[]{"aaa1","bbb1",null,null};
    private static ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
    static{
        HashMap map = null;
        for(int i=0;i<title.length;i++){
            map = new HashMap();
            map.put("title", title[i]);
            if(i>=desc.length) continue;
            map.put("desc", desc[i]);
            list.add(map);
        }
    }

原创粉丝点击