RoundedImageView,實現圓形、圓角矩形的注意事項

來源:互聯網
上載者:User

標籤:

RoundedImageView是gitHub上面的一個開源組件(https://github.com/vinc3m1/RoundedImageView),實現一些圓形或者圓角矩形是很方便的,

 1 <com.makeramen.roundedimageview.RoundedImageView 2                 android:id="@+id/iv_hint" 3                 android:layout_width="@dimen/x36" 4                 android:layout_height="@dimen/x36" 5                 android:src="@drawable/icon_no_photo_round" 6                 android:scaleType="centerCrop" 7                 app:riv_corner_radius="@dimen/x18" 8                 app:riv_border_color="@color/white50" 9                 app:riv_border_width="@dimen/x1"10                 app:riv_tile_mode="clamp"11                 app:riv_oval="true"12                 app:riv_mutate_background="true"13                 />

 

其中,riv_corner_radius是指圓角的大小,簡單來說,等於寬度一半時,就是圓形了;小於寬度的一半就是圓角矩形了。

這裡特別要注意的幾點:

1、riv_tile_mode 有三種clamp,repeat,mirror,分別是指縮放、重複、鏡像,實現後兩種的效果,最後是src的解析度小於RoundedImageView的解析度才比較直觀顯示(如這裡121x121---》70x70):

2、src原圖與RoundedImageView的比例關係,使用時要注意設定android:scaleType="",一般來說,有fitCenter,centerCrop,CenterInside,fitXY等幾種(具體區別可以看http://www.cnblogs.com/chq3272991/p/5710498.html)

    如要獲得一個圓形,如果src的長寬比為4:3,如果設定fitCenter,把原圖按比例擴大或縮小到ImageView的高度,置中顯示,那麼效果如下:

原圖:

顯然是得不到一個圓形的,那麼試試改成fitXY、center、centerCrop:

這過程也就是說,要先通過scaleType來調整(裁剪)原圖,然後再進行切圓角、加邊框處理,這裡用centerCrop才符合要求。類似的還有很多,大家遇到可以提出來共同探討下。

RoundedImageView,實現圓形、圓角矩形的注意事項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.