[英]How can I send an image from an ImageView in one activity to an ImageButton in another activity. Android Studio
[英]Android: How to prevent image from being scaled in ImageView or ImageButton?
如果使用“fill_parent”或使用“weight”拉伸視圖或按鈕,如何防止我的位圖在ImageView或ImageButton中自動縮放?
例如,這將在屏幕頂部創建一個4按鈕工具欄,其中按鈕的間距相等,但即使我使用scaleType =“center”,按鈕內的圖像也會保持拉伸狀態,這將是有用的,這應該可以防止根據文檔縮放,但事實並非如此。
任何見解都表示贊賞!
謝謝,
我發現當使用android:background時會自動將你在那里使用的圖像縮放到View的大小。
我嘗試使用android:src將圖像放在視圖中。 圖像沒有縮放,但我無法使圖像相對於視圖的大小居中。
所以我嘗試將整個Button設置為自己的相對布局,這就是我使用的:
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageButton android:id="@+id/ImageButton01"
android:layout_height="fill_parent"
android:layout_width="fill_parent"></ImageButton>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/cardback1"
android:layout_centerInParent="true"></ImageView>
</RelativeLayout>
ImageButton位於后台,並且始終與布局大小相同。 然而,ImageView將始終保持在RelativeLayout的中心,並且不會縮放。 這樣,RelativeLayout本身可以增長和移動,按鈕頂部的圖像將始終保持相同的大小,但按鈕將增長。 但是,如果布局變得比圖像本身小,則圖像會縮小。
我認為這就是你要找的東西。 可能有更好的方法來做到這一點,但這就是我現在能想到的。
只需修改您的drawable,應用更大的透明背景。 說我在hdpi中的drawable是41 * 48 px icon.png 我用透明背景創建了一個60 * 60像素的新圖像,復制粘貼上一個icon.png並以相同名稱保存。 這樣您就不需要觸摸布局了。
然后你可以檢查更大的按鈕區域,如果你應用一個非透明的 android:background :
<ImageButton android:id="@+id/widget_open"
android:src="@drawable/icon_widget_arrow_up"
android:background="#ff777777"
android:layout_height="wrap_content"
android:layout_width="wrap_content"></ImageButton>
將以前和新的drawable應用到android:src ,你應該清楚地看到ImageButton區域。
順便說一句,我在兼容模式下運行應用程序。
如果縮放圖像,請確保您沒有在兼容模式下運行應用程序(例如,如果您在不支持多個密度的情況下定位Android 1.5 / 1.6並且在Android 2.0上運行該應用程序。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.