了解支持乘法屏幕

whi*_*key 9 android multiplying android-screen-support

我知道有很多关于我的问题的信息,我几乎已经阅读了所有这些 - 关于developer.android.com的官方文档,XDA开发人员和这里的帖子,以及许多其他但仍有问题我希望你能解释一下.所以我在主屏幕上有一个带有仪表板图标的应用程序,我需要在所有现有屏幕上看到这个屏幕看起来一样,这里是肖像和土地标准:

MAIN_PORTRAIT 大陆

为了做到这一点,我已经在我的项目中添加了下一个文件夹:

在此输入图像描述

所有尺寸,如图像大小,文字大小和边距,我都在dimens.xml中为每个屏幕分辨率设置,我认为这足以在不同的设备上看到相同的图片.但我错了,在相同的分辨率但不同的屏幕尺寸下它看起来不同.这是一个带有mdpi的3.2"和5.1"屏幕:

屏幕3.2 屏幕5.1

我没有得到我应该添加像" values-mdpi-sw320dp "等文件夹或者还有其他方式我应该知道在所有屏幕上看到相同的图片?这是设置尺寸的所有尺寸的正确方法吗?请向我解释一下.问候.

Pas*_*llo 4

您不需要指定所有这些不同的尺寸来实现像这样简单的屏幕。只需尝试一下布局即可。例如,让我们看一下您的第一个屏幕。您可以使用 TableLayout 甚至内部有 N LinearLayout 的垂直 LinearLayout。此时只需使用重量即可!示例:想要一个包含两行和每行三个方形图像的网格:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />
</LinearLayout>

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />

    <ImageView
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight=".33" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

不幸的是,这对你来说仍然不够。您可能想要完成的另一件事是仍然让您的图像具有平方比。要实现这一点,只需像这样扩展图像视图:

public class SquaredImageView extends ImageView {

public SquaredImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
             int width = MeasureSpec.getSize(widthMeasureSpec);
             int height = width;
             setMeasuredDimension(width, height);

}
Run Code Online (Sandbox Code Playgroud)

}

现在只需提供正确密度的图像,一切都会完全按照您想要的样子