[英]ImageView with right-aligned, cropped, unscaled content
我一直在搜索,擺弄和哭泣了好幾個小時,但無法弄清楚如何將圖像放置到ImageView中,以及如何將圖像呈現為未縮放,右對齊以及裁剪超出ImageView左側的溢出。
ImageView的定義如下:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/bleh"
></ImageView>
layout_width
設置為fill_parent
以拉伸和縮小ImageView以適合屏幕。
layout_height
設置為wrap_content
因為ImageView始終具有固定的高度(根據圖像確定)。
我尚未定義layout_gravity="right"
因為我的理解是這與ImageView在其父級內部的位置有關,在這種情況下,由於ImageView的寬度設置為fill_parent,因此該設置無效。
使用上面的布局代碼,圖像可以縮放以適合ImageView。 我可以防止縮放的唯一方法是設置android:scaleType="center"
,它可以防止縮放,但不幸的是使圖像居中。
有想法嗎? 否則,我目前正在嘗試以下替代方法:
而不是滾動視圖-將圖像放在LinearLayout或RelativeLayout內。 使布局的layout_width fill_parent和layout_height包裝內容。 然后在ImageView上,使用布局重力right和wrap_content分別設置寬度和高度。
<LinerLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bleh"/>
</LinearLayout>
@harmanjd:您做了一個小錯誤,這是正確的方法:(對不起,我無法評論您的回答)
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bleh"/>
/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.