卡屏

解决ListView,GridView,Gallery的Adapter中的getView多次调...

我的未来我决定 提交于 2019-12-02 05:49:18
ListView,GridView,Gallery 这三个控件的加载自定义的内容的时候,你要加载三次,但是当你打印的时候,却发现他运行的不止三次,那时因为什么呢? 这是android机制中要计算高的时候出现的一些多次调用 具体的可以去网上查找 解决的方法就是 将控件的 android:layout_width="wrap_content" android:layout_height="wrap_content" 这连个属性给改为 android:layout_width="fill_parent" android:layout_height="fill_parent" 这样你可能会说那么我要给他指定高度呢? 很简单,不管你是要自适应呢,还是要给定标准的数据,只需要在控件的外面再添加一个parent即可 然后将 android:layout_width="wrap_content" android:layout_height="wrap_content" 或者是指定的参数给parent 即可! 特别是层层嵌套的话,更应该这么做了,要不然会出现卡屏的现象哦! 之前我做项目 <ListView> <GridView></GridView> </ListView> 使用的是 android:layout_width="wrap_content" android:layout_height=