0

私のコードで助けが必要です。 Android Studioがデフォルトで提供するナビゲーションドロワーコードを使用しようとしています。開始画面はcontent_main.xmlです。問題は、textviewなどをcontent_mainに置くと、切り替え時に他のフラグメント/アクティビティに表示されることです。フラグメント/ナビゲーションドロワーが重なっているTableLayout?

マイコード(私は2つの断片、relativeLayout & TableLayoutを持っているが、私は単純化のための1つを使用します):

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(); 
関連する問題