简体   繁体   English

针对不同的Android设备

[英]targeting different android devices

I know you can set specific layouts for a device like this: 我知道您可以为这样的设备设置特定的布局:

if(android.os.Build.MODEL.equals("Galaxy S II")){

        setContentView(R.layout.resultsGS2);
    }
    else if(android.os.Build.MODEL.equals("Nexus 7")){
        setContentView(R.layout.resultsN7);
    }
    else{

        setContentView(R.layout.results);
    }

But what I want is to make a layout for all devices that have similar screen size/dimensions. 但是我要为所有具有相似屏幕尺寸/尺寸的设备进行布局。 I have been looking at this: http://developer.android.com/guide/topics/resources/providing-resources.html and I tried renaming the layout folder many different things and whenever I try to edit an xml file in the new layout folder I made and I change the device preview it keeps changing back to the default layout. 我一直在看这个: http : //developer.android.com/guide/topics/resources/providing-resources.html ,我尝试重命名layout文件夹有很多不同的东西,并且每当我尝试在新版本中编辑xml文件时我创建的layout文件夹,更改了设备预览,它不断更改回默认布局。 I am using android studio, and basing the need to make a new layout off of the device previews that it shows. 我正在使用android studio,并且需要根据显示的设备预览进行新的布局。 Is there is an easier way to do this besides making a layout for each specific device? 除了为每个特定设备进行布局之外,还有其他更简便的方法吗?

This can be done by having different layout folders and calling them layout- + screen size name and then edit the layouts inside these folders to match the screen size you are targeting. 这可以通过以下方法完成:设置不同的布局文件夹,并layout- + screen size name ,然后在这些文件夹中编辑布局以匹配您要定位的屏幕尺寸。

So for example if you wanted to target something such as the galaxy nexus (320dpi) you would create a folder called layout-xhdpi and all the device specific layouts will be placed in here. 因此,例如,如果要定位诸如星系关系(320dpi)之类的东西,则可以创建一个名为layout-xhdpi的文件夹,并将所有设备特定的布局都放在此处。 And then if you were to run this in an emulator or a physical device you would see the layout that you made specifically for that screen size. 然后,如果要在仿真器或物理设备中运行此程序,则会看到专门为该屏幕尺寸制作的布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM