工作中經(jīng)常遇到加載圖片變形的問題,所以寫了這樣的一個(gè)imageview,使用場景是寬高中的一邊為match_parent或固定值,而另一邊為wrap_content的時(shí)候,可以根據(jù)輸入的寬高比自動(dòng)計(jì)算wrap_content所對(duì)應(yīng)的實(shí)際長度。當(dāng)兩邊都為wrap_content時(shí),沒有固定值做依據(jù),自動(dòng)計(jì)算的功能失效。
放上github地址
使用方法
<com.fenghebaiyang.aspectratioview.AspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/rem"
app:ratio="16:9" />
<com.fenghebaiyang.aspectratioview.AspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/rem"
app:ratio="1:1" />
<com.fenghebaiyang.aspectratioview.AspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/rem"
app:ratio="9:16" />
<com.fenghebaiyang.aspectratioview.AspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/rem"
app:ratio="h,9:16" />
<com.fenghebaiyang.aspectratioview.AspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/rem"
app:ratio="w,9:16" />
效果圖
QQ20170730-0.jpg