I add a fragment to the activity, and then I replace this fragment with a second fragment. After replacing the second action, the action panel moves a little down, as it happens 
My activity code
public class MyActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.meetinglist_activity); Fragment first_fragment = new FirstFragment(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.add(R.id.content_frame, first_fragment).commit(); }
Replacing the second fragment in the first part of the fragment by pressing
public class Firstfragment extends Fragment { FloatingActionButton new_fab; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View list_view=inflater.inflate(R.layout.meetingslist_fragment,container,false); new_fab=(FloatingActionButton)list_view.findViewById(R.id.meeting_new); new_fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment second_fragment = new SecondFragment(); FragmentTransaction ft =getActivity().getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, second_fragment).commit(); }
Action layout
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout> </LinearLayout>
Xml snippet
<?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"> <android.support.design.widget.FloatingActionButton android:id="@+id/meeting_new" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@android:drawable/ic_dialog_email" /> </android.support.design.widget.CoordinatorLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Large Text" android:gravity="center" android:id="@+id/textView" android:layout_gravity="center_horizontal" /> </LinearLayout>
I am using android.support.v4.app.Fragment;
I am using Android Studio version 2.0 and the latest API levels.
Can someone help me? Thank you in advance.
source share