0

내 코드에 도움이 필요합니다. Android Studio에서 기본적으로 제공하는 내비게이션 서랍 코드를 사용하려고합니다. 시작 화면은 content_main.xml이고 문제는 content_main에 textview 나 다른 것을 넣으면 전환 할 때 다른 프래그먼트/액티비티에 나타납니다.조각/탐색 서랍이 겹침 TableLayout?

내 코드 (I 두 조각하는 RelativeLayout의 & TableLayout을을 가지고 있지만 내가 단순 하나를 사용합니다) :

Registration_fragment.java

public class Registration_fragment extends Fragment { 
View myView; 
@Nullable @Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    myView = inflater.inflate(R.layout.registration_frag,container,false); 
    return myView; 
} 

content_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.company.myName.projectname.MainActivity" 
tools:showIn="@layout/app_bar_main"> 

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/content_frame" 
> 
</FrameLayout> 

registration_frag.xml

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

<TableRow> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/first_name" 
    android:layout_marginLeft="10dp" 
    android:id="@+id/fnametext" 
    /> 
    </TableRow> 
    ... </TableLayout> 

MainActivity.java는

public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 
    android.app.FragmentManager fragmentManager = getFragmentManager(); 
    if (id == R.id.nav_registration) { 
     // Handle the camera action 
     fragmentManager.beginTransaction().replace(R.id.content_frame, 
       new Registration_fragment()).commit(); 

    } else if (id == R.id.nav_records) { 
     fragmentManager.beginTransaction().replace(R.id.content_frame, 
       new Records_fragment()).commit(); 
    } else if (id == R.id.nav_signup) { 

    } else if (id == R.id.nav_manage) { 

    } else if (id == R.id.nav_share) { 

    } else if (id == R.id.nav_send) { 

    } 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
    return true; 
} 

정말 개념을 이해하고 도움을 사용할 수 있습니다.

답변

0

R.id.content_frame을 R.id.container로 변경해보십시오. 나는 당신이 팽창시키기 위해 용기를 사용하고있는 것을 본다. 비슷한 설정이 있지만 R.id.container와 잘 작동합니다.

fragmentManager.beginTransaction().replace(R.id.container, 
       new Registration_fragment()).commit();