2016-11-14 20 views
0

メインクラスのFragmentLayoutに問題があります。私の主な活動はマップ(Google API)であり、メニューはFragmentLayout(主なアクティビティXMLで)はwrap_content(高さ)、設定をクリックするとFragmentLayoutはショーですが、画面全体がちょうど一部で、設定の下で私は地図(そこにあるべきではない)を見る。私は私のFragmentLaoutのmatch_parentを設定すると、私の主なアクティビティからマップが表示されません。 は、ここに私のコードです。この目的のために、あなたはおそらくいうだけで(あなたのxmlが言うように)一つのメインコンテナを使用し、断片を交換したいと思いながらメインアクティビティのフラグメントコードが画面全体に表示されない

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    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" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="com.globallogic.cityguide.MainActivity" 
    android:id="@+id/mainLayout" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include layout="@layout/navigation_action" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" /> 
// THIS IS MY FRAGMENTS: 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" //here is this option which cover my whole screen when i put there match_parent 
      android:id="@+id/main_container" 
      android:layout_gravity="center" 
      > 
     </FrameLayout> 

     <include layout="@layout/activity_outdoor_map" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/navigation_view" 
     app:menu="@menu/navigation_menu" 
     app:headerLayout="@layout/navigation_action" 
     android:layout_gravity="start" 

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

</android.support.v4.widget.DrawerLayout> 

enter image description here

+0

「FrameLayout」に「1」の重みを与え、高さを「0」に設定します。 – PPartisan

+0

LinearLayoutをRelativeLayoutに置き換えます。 – zombie

+0

私はあなたがしたくないものを手に入れません。 高さがmatch_parentに設定されている場合のコンポーネントの動作は、親ビューで使用可能なすべての領域を塗りつぶすことになります。 何かを重複させたくない場合に、layout_aboveとlayout_belowと一緒にRelativeLayoutを使用することを考慮する必要があるすべての要素の相対位置を制御したい場合は、再度質問に答えることができません。 – c0rtexx

答えて

0

あなたは、別のコンテナを使用していますその中に。

このようにして、FrameLayoutを画面全体に合わせて設定し、必要に応じて設定のフラグメントとマップフラグメントを置き換えることができます。

したがって、MainActivityでコードを変更する必要があります。 のは、あなたのMainActivityが既にAppCompatActivityを拡張し、我々はmapFragmentのインスタンスを持っている、そしてあなたは、最初にそのような何かを、あなたの地図フラグメントをロードしたいと思うと仮定してみましょう:あなたは、設定ボタンを押したときに

// Add the fragment to the 'main_container' FrameLayout 
getSupportFragmentManager().beginTransaction().add(R.id.main_container, mapFragment).commit(); 

今、あなただけの置き換えられますフラグメント:

SettingsFragment settingsFragment = new SettingsFragment(); 
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 

// Replace whatever is in the main_container view with this fragment, 
// and add the transaction to the back stack if you want the user to be able to navigate back 
transaction.replace(R.id.main_container, settingsFragment); 
transaction.addToBackStack(null); 

// Commit the transaction 
transaction.commit(); 

さらに詳しい情報:here

0

あなたのレイアウトファイルでこれを追加することができます。そしてあなたのJavaファイルから他のメニューオプション。

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="342dp" 
    android:layout_height="473dp" android:id="@+id/map" tools:context=".MapsActivity" 
    android:name="com.google.android.gms.maps.SupportMapFragment" /> 

</LinearLayout> 
</LinearLayout> 
関連する問題