亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么 ImageButton 質量模糊或降低到最差?

為什么 ImageButton 質量模糊或降低到最差?

慕斯709654 2021-09-12 16:39:01
我的應用程序有一個質量太差的 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/圖形/矢量可繪制資源


查看完整回答
反對 回復 2021-09-12
?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

您實際上是在/mipmap目錄中引用像啟動器圖標這樣的圖像。

我建議減小您僅使用它的圖像大小ImageButton并將其放置在/drawable您想要的質量或可能小于當前質量的內部,而不是將其放置在/mipmap目錄中。

此外,我實際上沒有看到如何scaleType幫助ImageButton. 您可能也想刪除該行。


查看完整回答
反對 回復 2021-09-12
  • 2 回答
  • 0 關注
  • 180 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號