2016-08-03 18 views
1

Ich bin neu in Android Programmierung ein Ich habe ein Problem: Ich habe eine "Hauptseite" wo sind einige Tasten. Wenn ich das RelativeLayout durch mein Fragment ersetze, sind die Buttons über der Liste des Fragments. Wie kann ich die Buttons nach dem Start meines Fragments unsichtbar machen? Here is a Screenshot. All yellow marked are from the MainActivity and the list behind them is from the fragment. [LINK]Fragment ist unter den Tasten der MainActivity

Der wichtige Code:

public boolean onNavigationItemSelected(MenuItem item) { 
    // Handle navigation view item clicks here. 
    int id = item.getItemId(); 

    if (id == R.id.nav_functions) { 
     startFragment(FunctionsFragment.newInstance(1), "TagFunctions"); 
     Log.d("SMSAT", "nav_functions pressed"); 
    } else if (id == R.id.nav_macro) { 

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

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

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

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

    } 

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

private void startFragment(Fragment fragment, String tag){ 


    FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.replace(R.id.main_fragment_container, fragment, tag).commit(); 

    Log.d("SMSAT", "startFragment() ausgeführt"); 

} 

?xml version="1.0" encoding="utf-8"?> 
<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="de.mika.smsantitheft.MainActivity" 
tools:showIn="@layout/app_bar_main" 
android:id="@+id/main_relative_layout"> 


<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="@string/home_sms_commands" 
    android:id="@+id/textViewSmsBefehleStatus" 
    android:layout_marginTop="33dp" 
    android:layout_marginLeft="27dp" 
    android:layout_marginStart="27dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

    <ToggleButton 
    android:layout_width="140dp" 
    android:layout_height="wrap_content" 
    android:text="New ToggleButton" 
    android:id="@+id/toggleButton" 
    android:textOn="@string/aktivated" 
    android:textOff="@string/deaktivated" 
    android:layout_below="@+id/textViewSmsBefehleStatus" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_marginRight="30dp" 
    android:layout_marginEnd="30dp" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_functions" 
    android:id="@+id/button" 
    android:layout_below="@+id/toggleButton" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="49dp" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_macros" 
    android:id="@+id/button2" 
    android:layout_below="@+id/button" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_settings" 
    android:id="@+id/button3" 
    android:layout_below="@+id/button2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_contact" 
    android:id="@+id/button5" 
    android:layout_below="@+id/button3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/menu_recommend" 
    android:id="@+id/button4" 
    android:layout_below="@+id/button5" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /> 

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

    </RelativeLayout> 

Vielen Dank für Ihre Hilfe!

Antwort

0

Setzen Sie alle Tasten in ein Layout. Ändern Sie die gesamte Sichtbarkeit des Layouts.

0

Haben Sie versucht, in startFragment die Schaltflächen unsichtbar zu setzen?

Button button = (Button) findViewById(R.id.button_location); 
button.setVisibility(View.GONE); 
+0

Ok ich versuche es. Vielen Dank – Mika119

0

Versuchen Sie, die add-Methode zu verwenden, außer sie zu ersetzen.

Wenn das nicht hilft, versuchen Sie, das Thema Ihrer Appliation auf android: Theme.Material.Light zu setzen.

Wenn das nicht hilft, legen Sie den Hintergrund Ihres neuen Fragments auf XML in Weiß fest. Dadurch fühlen Sie sich wie ein anderes Blatt auf Ihrem Notebook.