我知道有很多关于我的问题的信息,我几乎读完了所有这些 - developer.android.com 上的官方文档、XDA-Developers 和此处的帖子,以及许多其他但仍然有它的问题,我希望你能向我解释一下。所以我有一个主屏幕上有仪表板图标的应用程序,我需要让这个屏幕在所有现有屏幕上看起来都一样,这里是肖像和陆地标准::
为了做到这一点,我在我的项目中添加了下一个文件夹:
我在 dimens.xml 中为每个屏幕分辨率设置了所有尺寸,例如图像尺寸、文本尺寸和边距,我认为这足以在不同设备上看到相同的图片。但是我错了,在相同的分辨率下不同的屏幕尺寸看起来是不同的。这是带有 mdpi 的 3.2"和 5.1"屏幕:
我不明白我应该添加像“values-mdpi-sw320dp”这样的文件夹,还是我应该知道在所有屏幕上看到相同图片的另一种方法?在尺寸中设置所有尺寸是否正确?请向我解释一下。此致。
最佳答案
您不需要指定所有这些不同的尺寸来获得像那个一样简单的屏幕。 简单地玩一下布局。 例如,让我们来看看你的第一个屏幕。您可以使用 TableLayout,甚至可以使用内部带有 N LinearLayout 的垂直 LinearLayout。此时只需使用重量! 示例:想要一个包含两行的网格和每行三个正方形图像:
<?xml version="1.0" encoding="utf-8"?>
<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>
不幸的是,这对您来说仍然不够。您可能想要完成的另一件事是让您的图像仍然具有方形比例。 要实现这一点,只需像这样扩展 ImageView :
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);
}
现在只需提供正确密度的图像,一切都会完全符合您的要求
关于android - 了解支持多屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20624989/