2016-11-14 4 views
0

Ich habe ein Problem mit meinem FragmentLayout in der Hauptklasse. Ich habe App für Standort, in meiner Haupttätigkeit ist Karte (Google API) und ich habe ein Menü, FragmentLayout (in meiner Haupttätigkeit XML) ist wrap_content (Höhe), wenn ich auf Einstellungen klicke, ist FragmentLayout Shows, aber es deckt nicht die Ganzer Bildschirm nur ein Teil und unter Einstellungen sehe ich Karte (die nicht dort sein sollte). Wenn ich Match_Parent für mein FragmentLaout einrichte, sehe ich die Karte nicht von meiner Hauptaktivität aus. Hier ist mein Code:Fragment Code in Hauptaktivität füllt nicht den gesamten Bildschirm

<?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

Geben Sie Ihrem 'FrameLayout' ein' Gewicht' von '1', und setzen Sie die Höhe auf' 0'. – PPartisan

+0

ersetzen LinearLayout mit RelativeLayout – zombie

+0

Ich bekomme nicht, was abgedeckt wird, dass Sie nicht wollen. Das Verhalten einer Komponente, deren Höhe auf "Match_parent" gesetzt ist, füllt den gesamten verfügbaren Platz in der übergeordneten Ansicht. Wenn Sie nicht möchten, dass sich etwas überlagert und Sie die relative Position jedes Elements steuern möchten, sollten Sie RelativeLayout zusammen mit layout_above und layout_below verwenden, aber Ihre Frage ist nicht klar genug, um sie richtig beantworten zu können. – c0rtexx

Antwort

0

Sie verwenden verschiedene Behälter, während für diesen Zweck würden Sie wahrscheinlich eher nur einen Hauptbehälter verwenden möchten (wie Ihre xml sagt) und die Fragmente ersetzen drin.

Auf diese Weise können Sie Ihr FrameLayout auf den gesamten Bildschirm einstellen und nur die Einstellungen Fragment und das Map-Fragment ersetzen.

Also sollte der Code in Ihrer MainActivity geändert werden. Ihres MainActivity Nehmen wir an bereits erweitert AppCompatActivity und wir haben eine Instanz von MapFragment, dann wollen Sie Ihre Karte Fragment zuerst, so etwas wie so laden:

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

jetzt, wenn Sie die Einstellungen Taste drücken, werden Sie nur ersetzen das Fragment:

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(); 

Weitere Informationen: here

0

Sie können dies in Ihrer Layout-Datei hinzufügen. Und andere Menüoption aus Ihrer Java-Datei.

<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> 
Verwandte Themen