您好,登錄后才能下訂單哦!
如何在Android中利用ImageView.src對圖片進(jìn)行拉伸處理?針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
方法如下:
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="205dp" android:scaleType="centerInside" android:background="@drawable/feature_guide_1" > </ImageView> </LinearLayout>
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@drawable/feature_guide_0" > </ImageView> </LinearLayout>
以下為參考內(nèi)容:
最近碰到一個需求,要求是在不知道圖片寬度和高度的情況下,讓圖片在指定寬度內(nèi)充滿,同時高度自適應(yīng),在網(wǎng)絡(luò)上查找了一下,也有很多解決方法,后來針對自己的應(yīng)用,選擇了一個修改較小的方案,最后證明效果還是蠻不錯的,記錄在這里,希望能幫助到有同樣需求的人。
首先,需要給你的ImageView布局加上Android:adjustViewBounds="true"
<ImageView android:id="@+id/test_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY" android:adjustViewBounds="true" android:layout_gravity="center" android:contentDescription="@string/app_name" android:src="@drawable/ic_launcher" />
然后,在代碼里設(shè)置ImageView.最大寬度和最大高度,因為adjustViewBounds
屬性只有在設(shè)置了最大高度和最大寬度后才會起作用
int screenWidth = getScreenWidth(this); ViewGroup.LayoutParams lp = testImage.getLayoutParams(); lp.width = screenWidth; lp.height = LayoutParams.WRAP_CONTENT; testImage.setLayoutParams(lp); testImage.setMaxWidth(screenWidth); testImage.setMaxHeight(screenWidth * 5);
關(guān)于如何在Android中利用ImageView.src對圖片進(jìn)行拉伸處理問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。