2016-06-22 7 views
3

私はアクティビティ、すなわちマテリアルデザインドロワ、およびユーザがドロワのオプションをクリックしたときにアクティビティjavaファイルから呼び出されるフラグメントを持っています。 問題はフラグメントのレイアウトがアクティビティのタイトルバーと重なり、アクティビティ内に配置されるのではなく、すべての画面に一致することです。 AndroidStudioプレビューでは、フラグメントのコンテンツが正しく設定されています enter image description hereフラグメントのレイアウトがアクティビティのタイトルバーと重複しています

しかし、私は自分の携帯電話にAPKをロードするとき、私はこのような何かを参照してください。 - fragment_layout: enter image description here

をここに私のソースコードがあります。 XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin"> 

    <EditText 
     android:id="@+id/subjectSelector" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="text" 
     android:hint="Write subject initials"/> 

    <Button 
     android:id="@+id/queryButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="end" 
     style="@style/Base.Widget.AppCompat.Button.Borderless" 
     android:text="Search" 
     android:layout_alignBottom="@+id/subjectSelector" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 

    <ProgressBar 
     android:id="@+id/progressBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_centerVertical="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/subjectSelector" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
      <TextView 
       android:id="@+id/subjectName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:id="@+id/subjectTeachers" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:id="@+id/subjectDescription" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:id="@+id/subjectCredits" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

Drawer.java

public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 
    Fragment newFragment; 
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
    if (id == R.id.nav_timetable) { 
     newFragment = new TimetableMainMenu(); 
    } else if (id == R.id.nav_notifications) { 
     newFragment = new NotificationsMainMenu(); 
    } else if (id == R.id.nav_schedule) { 
     newFragment = new ScheduleMainMenu(); 
    } else if (id == R.id.nav_class_availability) { 
     newFragment = new ClassAvailabilityMainMenu(); 
    } else if (id == R.id.nav_subject_info) { 
     newFragment = new SubjectInfoMainMenu(); 
    } else newFragment = null; 

    if (newFragment != null) { 
     transaction.replace(R.id.main_menu_fragment_container, newFragment); 
     transaction.addToBackStack(null); 
    } else { 
     Toast.makeText(MainMenuActivity.this, "Not implemented yet", Toast.LENGTH_SHORT).show(); 
    } 
    transaction.commit(); 

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

enter image description here

  • app_bar_main_menu.xml(申し訳ありませんが、私は、コード形式としてこれを更新することはできません)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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" 
    android:fitsSystemWindows="true" 
    tools:context="com.upc.fib.racopocket.MainMenuActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main_menu" /> 



</android.support.design.widget.CoordinatorLayout> 
  • content_main_menu.xml

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

私はこれをどのように修正することができますか?

+1

あなたの 'app_bar_main_menu.xml'を共有できますか?その他の後続のレイアウト – jitinsharma

答えて

0

私は答えを得た、それは単なる愚かなものでした。 content_main_menu.xmlでは、フレームレイアウトがすべての画面に一致しているので、marginButtonをactionBarSizeだけ残してしまっただけです。これは新しいcontent_main_menu.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/main_menu_fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="?attr/actionBarSize"/> 
関連する問題