首页 > 应用开发 > IT综合 > 解决直播商城源码中,getView被重复调用
直播商城源码的getView被调用次数,取决于当前屏幕能显示的item的数量,显示一个item就调用一次。当listview的layout_height属性是wrap_content时,有可能造成listview无法计算高度,相应的需要显示的item数量就无法计算,造成直播商城源码的getView多次被调用。
解决方案:
1:在listview外面套一层RelativeLayout,将listview高度设置为fill_parent。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/RelativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/repeat_bg"> <ListView android:id="@+id/friend_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:cacheColorHint="#00000000" android:divider="#CCCCCC" android:fastScrollEnabled="true" android:focusableInTouchMode="true" /> </RelativeLayout>
2:在listview外面套一层 LinearLayout,将listview高度设置为0dip。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f3f3f3" android:orientation="vertical" > <ListView android:id="@+id/requestObjLV" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:cacheColorHint="#00000000" android:divider="#CCCCCC" /> </LinearLayout>
通过以上两个方案,我们可以就可以解决直播商城源码的getView重复调用问题。
声明:本文由云豹科技转发自一叶飘舟博客,如有侵权请联系作者删除
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69982461/viewspace-2793686/ ,如需转载,请注明出处,否则将追究法律责任。