我的應用程序有一個質量太差的 ImageButton。實際圖像尺寸為 4176*4176(4176 像素),單獨打開時看起來完全沒問題。但是,當我將其導入 android studio 并將其分配給 ImageButton 時,圖像質量會下降。我一直在嘗試多種方法來解決這個問題,但還沒有成功。我對 Android 編程完全陌生。我轉到 res/drawable,然后右鍵單擊以創建一個新的圖像資產,然后指定導入 png 文件的位置。實際圖像:工作室內部圖像:這是activity_main.xml中的代碼:<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"android:gravity="center"android:orientation="vertical"><ImageButton android:id="@+id/police" android:layout_width="317dp" android:layout_height="295dp" android:layout_centerInParent="true" android:adjustViewBounds="true" android:scaleType="fitXY" android:background="@drawable/custom_button" /></LinearLayout>調用圖像的自定義按鈕代碼:<item android:state_pressed="true" android:drawable="@mipmap/pressed" /><item android:drawable="@mipmap/defaultt" /></selector>
2 回答

牛魔王的故事
TA貢獻1830條經驗 獲得超3個贊
我首先回顧一下 Android 上的密度無關像素。這是一個很好的博客,涵蓋了這個概念:https : //www.captechconsulting.com/blogs/understanding-density-independence-in-android
主要問題是您的圖像(分辨率非常高)被壓縮以適合圖像按鈕。通常,您希望通過不同的可繪制資源目錄(例如,drawable-hdpi、drawable-xhdpi、drawable-xxhdpi)包含不同密度的圖像資產。
但是,現在,您可以使用矢量可繪制對象,這將減少每個密度桶擁有多個資產的需要,假設您能夠生成 SVG 資產文件:https : //developer.android.com/guide/topics/圖形/矢量可繪制資源

炎炎設計
TA貢獻1808條經驗 獲得超4個贊
您實際上是在/mipmap
目錄中引用像啟動器圖標這樣的圖像。
我建議減小您僅使用它的圖像大小ImageButton
并將其放置在/drawable
您想要的質量或可能小于當前質量的內部,而不是將其放置在/mipmap
目錄中。
此外,我實際上沒有看到如何scaleType
幫助ImageButton
. 您可能也想刪除該行。
添加回答
舉報
0/150
提交
取消