Android 为什么不是';是否正在访问我的布局大型文件夹?

Android 为什么不是';是否正在访问我的布局大型文件夹?,android,android-layout,Android,Android Layout,下面的类从不调用layout large文件夹中的布局。这是下面的maintabletlayout.xml文件。我使用的avd分辨率为800x1280,密度为160。下面的findViewById()始终返回null。有什么想法吗?系统必须具备哪些规格才能访问layout large文件夹 public class MainActivity extends Activity { boolean mTwoPane; /** Called when the activity is first cr

下面的类从不调用layout large文件夹中的布局。这是下面的maintabletlayout.xml文件。我使用的avd分辨率为800x1280,密度为160。下面的findViewById()始终返回null。有什么想法吗?系统必须具备哪些规格才能访问layout large文件夹

public class MainActivity extends Activity
{
 boolean mTwoPane;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    ArrayList<String> subjects=new ArrayList<String>();
    subjects.add("Math");
    subjects.add("Science");
    subjects.add("Art");
    if(findViewById(R.id.top_tablet_container)!=null){
       mTwoPane=true; 
    }else{
        mTwoPane=false;
    }

    if(mTwoPane){
        setContentView(R.layout.maintabletlayout);
        SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
        getFragmentManager().beginTransaction().add(R.id.list_container, top).commit();
    }else{

        setContentView(R.layout.mainphonelayout);
        SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
        getFragmentManager().beginTransaction().add(R.id.top_phone_container, top).commit();

    }
}
}
公共类MainActivity扩展活动
{
布尔mTwoPane;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ArrayList主题=新建ArrayList();
科目。添加(“数学”);
主题。添加(“科学”);
主题。添加(“艺术”);
if(findViewById(R.id.top\u平板电脑\u容器)!=null){
mTwoPane=true;
}否则{
mTwoPane=false;
}
如果(mTwoPane){
setContentView(R.layout.maintabletlayout);
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.list_容器,顶部).commit();
}否则{
setContentView(R.layout.mainphonelayout);
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.top\u phone\u容器,top).commit();
}
}
}
mainphonelayout.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/top_phone_container"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/top_tablet_container"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >
<RelativeLayout
    android:id="@+id/list_container"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:layout_toLeftOf="@+id/content_container"
  >


</RelativeLayout>

<RelativeLayout
    android:id="@id/content_container"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
   android:layout_weight="1"
    android:layout_toRightOf="@id/content_container"
  >

</RelativeLayout>
</LinearLayout>

maintabletlayout.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/top_phone_container"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
>

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/top_tablet_container"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >
<RelativeLayout
    android:id="@+id/list_container"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="2"
    android:layout_toLeftOf="@+id/content_container"
  >


</RelativeLayout>

<RelativeLayout
    android:id="@id/content_container"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
   android:layout_weight="1"
    android:layout_toRightOf="@id/content_container"
  >

</RelativeLayout>
</LinearLayout>

在舱单上我也有这个

<supports-screens
   android:xlargeScreens="true"
   android:largeScreens="true"
   android:normalScreens="true"
   android:anyDensity="true" />


@诺伊德的回答是正确的。我必须给两个布局赋予相同的名称,然后用该名称设置ContentView()。通过这种方式,您可以为适当大小的屏幕设置内容视图,然后当尝试在大屏幕布局中查找id时,findViewById()能够返回非null

 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);


        ArrayList<String> subjects=new ArrayList<String>();
        subjects.add("Math");
        subjects.add("Science");
        subjects.add("Art");
        if(findViewById(R.id.top_tablet_container)!=null){
           mTwoPane=true; 
        }else{
            mTwoPane=false;
        }

        if(mTwoPane){

            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.list_container, top).commit();
        }else{


            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.top_phone_container, top).commit();

        }
    }
 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);


        ArrayList<String> subjects=new ArrayList<String>();
        subjects.add("Math");
        subjects.add("Science");
        subjects.add("Art");
        if(findViewById(R.id.top_tablet_container)!=null){
           mTwoPane=true; 
        }else{
            mTwoPane=false;
        }

        if(mTwoPane){

            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.list_container, top).commit();
        }else{


            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.top_phone_container, top).commit();

        }
    }
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList主题=新建ArrayList();
科目。添加(“数学”);
主题。添加(“科学”);
主题。添加(“艺术”);
if(findViewById(R.id.top\u平板电脑\u容器)!=null){
mTwoPane=true;
}否则{
mTwoPane=false;
}
如果(mTwoPane){
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.list_容器,顶部).commit();
}否则{
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.top\u phone\u容器,top).commit();
}
}

由于Android 3.2,您应该使用
布局swXXXdp
符号,其中
XXX
是数字。在您的情况下,应该是
720
,一个10英寸的屏幕

确保您正在运行的模拟器确实已配置为“大”。分辨率范围不会自动应用于大小“bucket”(正常/大/…)。
@nOiAd的答案是正确的。我必须为两个版面指定相同的名称,然后使用该名称设置ContentView()。这样,您可以为适当大小的屏幕设置内容视图,然后在尝试在大屏幕版面中查找id时,findViewById()可以返回非null

 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);


        ArrayList<String> subjects=new ArrayList<String>();
        subjects.add("Math");
        subjects.add("Science");
        subjects.add("Art");
        if(findViewById(R.id.top_tablet_container)!=null){
           mTwoPane=true; 
        }else{
            mTwoPane=false;
        }

        if(mTwoPane){

            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.list_container, top).commit();
        }else{


            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.top_phone_container, top).commit();

        }
    }
 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.main);


        ArrayList<String> subjects=new ArrayList<String>();
        subjects.add("Math");
        subjects.add("Science");
        subjects.add("Art");
        if(findViewById(R.id.top_tablet_container)!=null){
           mTwoPane=true; 
        }else{
            mTwoPane=false;
        }

        if(mTwoPane){

            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.list_container, top).commit();
        }else{


            SubjectListFragment top=new SubjectListFragment(subjects,mTwoPane);
            getFragmentManager().beginTransaction().add(R.id.top_phone_container, top).commit();

        }
    }
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList主题=新建ArrayList();
科目。添加(“数学”);
主题。添加(“科学”);
主题。添加(“艺术”);
if(findViewById(R.id.top\u平板电脑\u容器)!=null){
mTwoPane=true;
}否则{
mTwoPane=false;
}
如果(mTwoPane){
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.list_容器,顶部).commit();
}否则{
SubjectListFragment top=新的SubjectListFragment(主题,mTwoPane);
getFragmentManager().beginTransaction().add(R.id.top\u phone\u容器,top).commit();
}
}

你能试试像300这样的更高密度吗将始终返回null,因为您以前没有显示任何视图id。此视图id应仅在大型设备上显示,您能详细说明吗?我使用的是克隆的nexus 7 avd,没有LuckwWhy 720指定10英寸屏幕?我使用的是7英寸avd,并将文件夹更改为您建议的名称,但我运气不佳。我还尝试了layout-sw800dp和layout-sw600dp不走运。它在android文档中。sw600dp代表7英寸。您给minSdkVersion和targetSkdVersion赋予了什么值?这里是文档:谢谢,我已经在清单中添加了XLargeScreenses属性,并将文件夹重命名为layout-sw800dp,用于我的800x1280显示器。仍然不起作用。根据文档n应为布局图-sw720dp