compile 'com.joooonho:selectableroundedimageview:1.0.1'
起初做項目,需要輪播圖123.jpg
一看這種,圖片,肯定想到的是以前用過的圓角圖片控件,做成選項卡的樣式,但是之后測試的時候發現,在該輪播圖界面鎖屏后,再解鎖,程序內存溢出了。。。
用Glide加載圖片
Glide.with(context).load(list.get(position).getImage()).placeholder(R.mipmap.no_img2).dontAnimate().error(R.mipmap.no_img2).into(img);
得加上.dontAnimate()
否則報錯
看Memory,發現每次切換一張輪播圖,內存就會加2M。。。。
這可是個大問題
125.jpg
124.jpg
每次滑動一次輪播圖就能加2M左右,測試大概到能到170M左右的內存后就會溢出,這問題果斷是換一個控件,最后找到一個,就是用Imageview,再加上一個圓角的覆蓋,也能實現這種效果
。
<com.gcssloop.widget.RCRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="20dp"
app:round_corner_bottom_left="5dp"
app:round_corner_bottom_right="5dp"
app:round_corner_top_right="5dp"
app:round_corner_top_left="5dp">
<ImageView
android:id="@+id/tra_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/no_img"
android:scaleType="centerCrop"
android:background="@color/white" />
</com.gcssloop.widget.RCRelativeLayout>
compile 'com.gcssloop.widget:rclayout:1.4.1@aar'
allprojects {
repositories {
jcenter()
maven { url "http://lib.gcssloop.com:8081/repository/gcssloop-central/" }
}
}
這樣再次看memory,
126.jpg
125.jpg
每次基本上增加知識0.04M大概在占用內存到達40M左右的時候會內存回收,不會造成內存溢出
用的輪播圖控件是ultraviewpager,怎么使用,見原作者的Github,有詳解
https://github.com/alibaba/UltraViewPager/blob/master/README-ch.md