如何在android中实现多屏幕大小的配置均衡器



我正在设计支持多屏幕大小的应用程序,在3.2中使用类似margin_top等的dip。我必须为值文件夹创建哪些文件夹?我必须在哪里指定倾角?有人能告诉我怎么做吗?如果我给了值-11文件夹和加载布局。我得到了一个编译错误no resource found error,但我在那里有布局。

感谢

有多种切换布局的方法。以下是前两个:

假设在您的代码中,您要膨胀R.layout.my_layout

  • 通过向布局添加选择器直接切换

机具布局:

res/layout/my_layout.xml
res/layout-land/my_layout.xml
res/layout-w600dp/my_layout.xml
  • 通过向值添加选择器来间接切换

机具布局:

res/layout/my_layout_narrow.xml
res/layout/my_layout_wide.xml

机具值:

res/values/layouts.xml
    <resources>
        <item name="my_layout" type="layout">@layout/my_layout_narrow</item>
    </resources>
res/values-land/layouts.xml
    <resources>
        <item name="my_layout" type="layout">@layout/my_layout_wide</item>
    </resources>
res/values-w400dp/layouts.xml
    <resources>
        <item name="my_layout" type="layout">@layout/my_layout_narrow</item>
    </resources>
res/values-w800dp/layouts.xml
    <resources>
        <item name="my_layout" type="layout">@layout/my_layout_wide</item>
    </resources>
Use dp instead of dip and put the below lines in The Android Manifest.xml file above <application/> tag & put your all images in simply drawable folder .Doing all these changes your app support all screen sizes.`<supports-screens 
          android:smallScreens="true" 
          android:normalScreens="true"
          android:largeScreens="true" 
          android:anyDensity="true"  >
          </supports-screens>

请参阅指南主题"支持多屏幕>声明Android 3.2版平板电脑布局"。您可以为可用宽度和高度或最小宽度指定资源文件夹。例如,您可能有

  • res/values-sw600dp,当应用程序可用的最小屏幕尺寸至少为600dp时,您将在其中定义margin_top
  • res/values-w1024dp,当应用程序可用的屏幕宽度至少为1024dp时,您将在其中定义margin_top

等等。

最新更新