当我打开我的应用时,出现的第一页是content_main_frame。当我填写我的content_main时,我在main_content中的内容不断出现在我的其他片段中。我该怎么办?
MainActivity:
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
int id = item.getItemId();
if (id == R.id.home) {
setTitle("home");
Home fragment = new Home();
FragmentTransaction fragmentTransaction = getSupportFragmentManager(). beginTransaction();
fragmentTransaction.replace(R.id.content_main_frame,fragment, "fragment1");
fragmentTransaction.commit();
} else if (id == R.id.second_fragment) {
setTitle("ABC");
SecondFragment fragment = new SecondFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager(). beginTransaction();
fragmentTransaction.replace(R.id.content_main_frame,fragment, "fragment2");
fragmentTransaction.commit();
} else if (id == R.id.third_fragment) {
setTitle("345");
ThirdFragment fragment = new ThirdFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager(). beginTransaction();
fragmentTransaction.replace(R.id.content_main_frame,fragment, "fragment3");
fragmentTransaction.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
这是我的content_main.xml布局:
`
<FrameLayout
android:id="@+id/content_main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="@+id/theotherone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="140dp"
android:paddingTop="1dp"
android:paddingBottom="60dp"
android:id="@+id/imageView1"
android:layout_gravity="center_horizontal|top"
android:src="@drawable/picture1"
android:contentDescription="@string/app_name"/>
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:paddingBottom="150dp"
android:id="@+id/imageview2"
android:layout_gravity="center"
android:src="@drawable/picture2"
android:contentDescription="picture for hjem 2"/>
<ListView
android:id="@+id/ListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:clickable="false"
android:drawSelectorOnTop="false"
android:listSelector="@android:color/transparent"
android:divider="@null"
android:paddingBottom="55dp">
</ListView>
</FrameLayout>
`