我是Android編程新手我有一個問題: 我有一個「主頁」,其中有一些按鈕。如果我用我的片段替換RelativeLayout是片段列表上的按鈕。在我開始我的片段之後,如何讓按鈕隱形? Here is a Screenshot. All yellow marked are from the MainActivity and the list behind them is from the fragment. [LINK]片段是在MainActivity的按鈕下
重要的代碼:
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>
感謝您的幫助!
好吧,我試試看。謝謝 – Mika119