2017-10-28 77 views
0

中添加地址布局 - 小activity.xml你好我与本教程https://stackoverflow.com/q/7665194/840861使res/layout-small/my_layout.xml和我想在主要活动中添加此xml文件,但不能解决它像这样教程https://android-developers.googleblog.com/2011/07/new-tools-for-managing-screen-sizes.html如何在类

我想这样的代码:

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); 
    } 
} 
} 

我的代码是:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    setContentView(R.layout.activity_main); 
} 

,但不能这个地址的xml:

setContentView(R.layout-small.activity_main); 

和我创造佳绩的文件夹布局小和过去的xml文件activity_main但不能添加地址

对不起我不是良好的英语语言

回答

0

使RES /布局小/ my_layout.xml

没有理由创建res/layout-small/目录。这与res/layout/具有相同的效果,并称这些资源用于每种屏幕尺寸。

大小预选赛(-small-normal-large-xlarge,他们更现代的等价物像-w640dp)说:“利用这些资源,这通常就是这个尺寸或更大”。因此,在-small-normal屏幕上不会使用res/layout-large/资源,并且在当前宽度小于640dp的设备上不会使用res/layout-w640dp/资源。但所有屏幕都是-small或更大,因此res/layout-small/将匹配每个设备。


setContentView(R.layout-small.activity_main); 

当你使用的资源,你永远不会把预选赛替换有:

setContentView(R.layout.activity_main);