所以我这里有一张图片,我通过将它们放入不同的可绘制文件夹中创建了该图片的多个副本。
<ImageView
android:id="@+id/Profile_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="@string/profile_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/profile_bar"
android:focusable="true" />
现在我的问题是我的应用程序的设计在某些屏幕尺寸上看起来很完美,但对于其他屏幕尺寸来说,它看起来不太好。
例如,我的应用程序设计在 Nexus 5 上看起来很完美,但当我换成 Pixel 时,即使屏幕尺寸相同,它也会乱七八糟。我了解到 dpi 不同,这就是它搞砸的原因。
那么,如何支持不同 dpi 的相同屏幕尺寸?
编辑:链接到 Nexus 5 和 Pixel 上的屏幕外观 - https://imgur.com/a/iMeSwV8
编辑 2:我决定如何设计我的三张图片的 XML 代码。现在的设计是正确的,除了一件事。这三个图像没有出现在屏幕顶部,而是出现在屏幕中央。如果我可以将这些图像移到顶部,我的问题就会得到解决。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/Profile_Button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:contentDescription="@string/profile_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/profile_bar"
android:focusable="true" />
<ImageView
android:id="@+id/Game_Button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:contentDescription="@string/game_button"
app:layout_constraintEnd_toStartOf="@+id/Messages_Button"
app:layout_constraintStart_toEndOf="@+id/Profile_Button"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/podium_bar"
android:focusable="true" />
<ImageView
android:id="@+id/Messages_Button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:contentDescription="@string/messages_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/messages_bar"
android:focusable="true" />
</LinearLayout>
最佳答案
首先,如果您提供更多信息,例如 Activity XML 代码以及您真正期望的内容,我们将不胜感激。但我给出了一些可能有用的提示。
首先,将具有不同分辨率的不同图像放在可绘制文件夹中会导致加载与手机分辨率相匹配的图像。对于更高分辨率、更高质量的图像,对于较低的分辨率,图像具有更小的尺寸和分辨率。如果您将 1 张图像放入文件夹中,android 具有自动调整大小功能,可以调整手机图像的大小。因此,如果质量不佳,它在高分辨率下可能会模糊。
在您的问题中,两部手机都加载相同的图像,因为它们具有相同的分辨率。所以问题不是由这些图像引起的。
其次,要使您的应用在所有纵横比和分辨率下看起来都一样,最重要的是布局的方式。我喜欢 LinearLayout 因为它适合所有情况。将一些 LinearLayout 放在彼此内部并花一些时间使它们看起来不错,因为您可以确信它在任何情况下都会很好。
对于您的情况:尝试 1 个水平 LinearLayout 和 3 个 child (imageview)。将所有权重设置为 1。然后无论每个屏幕尺寸如何,它们都将以相同尺寸填充屏幕顶部。
关于java - 如何支持相同的屏幕尺寸但不同的 dpi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54044079/