[英]Understanding supporting different screen sizes relating to Images
我在應用程序中對圖像的正確視圖仍然存在問題。 因此,在我的第一台設備(5,2英寸和480密度)上,它看起來不錯。
在第二台設備(5.5英寸和420密度)上,圖像不合適,並且顯示白色邊框。
這是我布局中的ImageView:
<ImageView
android:id="@+id/iv_image"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/tv_topic" />
在Android博客上閱讀以下內容后,我將所有圖片都放在了drawable文件夾中:
通常,有兩種方法可以將所有屏幕DPI作為目標。 1.最簡單的方法-使所有圖像達到超高或超高DPI。
如果設備與可繪制DPI不匹配,則Android自動縮放可繪制。 如果僅以高密度創建可繪制對象,則較低的DPI屏幕將按比例縮小資源以適合布局。
因此,我在可繪制文件夾中以盡可能最高的分辨率實施了所有圖像。 是否有必要將它們全部放在特定的文件夾中(drawable-ldpi,drawable-mdpi ...)? 這意味着將有我的圖像的多個副本,並且始終具有相同的大小。
是的,我幾次閱讀了支持多個屏幕的官方文檔。 但是我在理解它時有一些問題。
我建議您使用layout_weight屬性來保持ImageView和問題布局之間的恆定比率。 將布局更改為以下內容:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/iv_image"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="3" />
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.