Ну, у меня есть MainActivity с FrameLayout, у которого есть ViewPager и TabLayout. В ViewPager есть 3 фрагмента, и у каждого фрагмента есть кнопка.
Я хочу сделать это так, скажем, когда вы нажмете кнопку на первом фрагменте, он заменит (уничтожит) всю структуру кадра другим фрагментом. Проблема заключается в том, что ViewPager и TabLayout (те, что находятся внутри framelayout) остаются видимыми, и появляется новый фрагмент, который должен их заменить, но перекрывает его.
Вот код:
main_activity_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/starIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/Star_Number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toLeftOf="@id/starIcon"
android:text="0"
android:textSize="26sp" />
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<android.support.design.widget.TabLayout
android:id="@+id/tabDots"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_gravity="bottom"
app:tabBackground="@drawable/tab_selector"
app:tabGravity="center"
app:tabIndicatorHeight="0dp" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<Button
android:id="@+id/Go_Back_Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Go back" />
</LinearLayout>
Фрагмент с кнопкой, которая должна заменить FrameLayout новым Фрагментом
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_addition_box, container, false);
additionBox = v.findViewById(R.id.Addition_Box);
additionBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().
getSupportFragmentManager().
beginTransaction().
replace(R.id.mainLayout, AdditionLevelsFragment.newInstance(), null).
addToBackStack(null).commit();
}
});
return v;
}
введите описание изображения здесь
введите описание изображения здесь
Фрагмент, который должен заменить FrameLayout, содержит «Уровни добавления».