【问题标题】:Seven inch tablet layout issue七寸平板布局问题
【发布时间】:2017-01-20 12:02:59
【问题描述】:

我正在开发一个支持多屏的应用。我为所有 10 英寸平板电脑使用 layout-sw720dp 文件夹,为所有智能手机和 7 英寸平板电脑使用 layout 文件夹。 我在 Lanix Ilium Pad T7 http://phoneradar.com/gadgets/phones/lanix/ilium-pad-t7/ 中测试了我的应用程序,它没有从布局文件夹中获取布局。我尝试添加 layout-sw600dp 和 layout-sw600dp-hdpi 文件夹,但此设备仍在从 layout-sw720dp 获取布局。

我必须做什么才能从不同于 layout-sw720dp 的另一个文件夹中获取布局?

【问题讨论】:

    标签: android android-layout layout screen-density


    【解决方案1】:

    资源应该是这样的。但如果它不适合您,请尝试在其他设备上进行测试。您可以使用非常有用的工具,例如 this (Genymotion),在我看来,非商业用途是最好的。

    res/layout/main_activity.xml           # For phones
    res/layout-sw600dp/main_activity.xml   # For 7” tablets
    res/layout-sw720dp/main_activity.xml   # For 10” tablets
    

    您也可以随时简单地选择要在代码中使用的资源

    public class MyActivity extends Activity {
            @Override protected void onCreate(Bundle savedInstanceState) {
                super.onCreate();
    
                Configuration config = getResources().getConfiguration();
                if (config.smallestScreenWidthDp >= 600) {
                    setContentView(R.layout.main_activity_tablet);
                } else {
                    setContentView(R.layout.main_activity);
                }
            }
        }
    

    【讨论】:

    • 我尝试在代码中选择资源,但是属性smallestScreenWithDp返回720,这正常吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-04
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    相关资源
    最近更新 更多