A lane that moves when replaced by a fragment

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 enter image description here

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

 <!--First Layout--> <?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> <!--Second 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"> <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.

+5
source share
3 answers

The problem meets the layout of the Bcoz coordinate. In the first fragment, just put the coordinate layout in the second fragment so that it works the same for both layouts.

+3
source

Just change this line

Android: fitsSystemWindows = "true"

to

Android: fitsSystemWindows = "false"

I am sure that your problem will be solved.

+2
source

I think that to solve all the problems associated with the action bar, you should use the toolbar, which is a new replacement for the old Google action bar. You can find the toolbar implementation guide at the end of the link: http://javatechig.com/android/android-lollipop-toolbar-example

0
source

Source: https://habr.com/ru/post/1244431/


All Articles