Android 마커를 사용하고 ViewPager
을 사용하여 세 조각을 모두 포함하는 앱을 만들었습니다. 주요 액티비티는 "activity_main.xml"에 포함되어 있으며 을 포함하며 inturn에는 PagerTitleStrip
이 포함됩니다. 내 MainActivity는 지원 라이브러리에서 FragmentActivity
을 확장합니다.타블렛의 다른 조각보기
나는 Android 개발자에게 Supporting Multiple Screens을 확인했습니다. "layout-sw600dp"라는 폴더를 만들고 거기에 또 하나의 "activity_main.xml"을 추가했습니다. 나는 거기에 내 단편을 LinearLayout
안에 추가했습니다. 이 앱을 7 인치 태블릿에서 실행하면이 행의 NPE로 앱이 종료됩니다. mViewPager.setAdapter(mSectionsPagerAdapter);
이 NPE는 sw600dp 폴더에서 내 xml을 호출하기 때문에 여기에 표시됩니다.하지만 어떻게 지정합니까? ? 정제에 대한 단일 뷰에서 여러 조각
어떤 도움이나 포인터를 이해할 수있을 것이다
편집 -. 일부 소스 코드를 추가, 포스트 짧은
으로 유지에만 해당 데이터를 유지하려 당신은 아래에서 찾을 수 있습니다, 대부분의 코드는에 의해 생성됩니다 마법사/adt-plugin.
레이아웃/activity_main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
레이아웃 sw600dp/activity_main.xml는
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/fragment_one"...
<fragment
android:id="@+id/fragment_two"...
MainActivity.java는
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the adapter that will return a fragment for each of the three primary sections
// of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding tab.
// We can also use ActionBar.Tab#select() to do this if we have a reference to the
// Tab.
mViewPager.setOnPageChangeListener(...
문제를 더 잘 이해할 수 있도록 몇 가지 코드를 게시하십시오. 당신이 말했던 것에서, 당신은 타블렛 레이아웃에서 호출기를 사용하지 않으므로, 코드에서 그것을 사용하지 않는 체크를 추가하고 linearLayout에서 프래그먼트를 표시하십시오. –