Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fragments not being displayed properly #481

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/ru/nsu/ccfit/zuev/osu/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.nsu.ccfit.zuev.osu;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ComponentName;
Expand Down Expand Up @@ -31,6 +33,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.Toast;

import androidx.core.app.NotificationManagerCompat;
Expand Down Expand Up @@ -366,26 +369,21 @@ protected void onSetContentView() {
this.mRenderSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
this.mRenderSurfaceView.setRenderer(this.mEngine);

RelativeLayout layout = new RelativeLayout(this);
layout.setBackgroundColor(Color.BLACK);
layout.addView(
mRenderSurfaceView,
new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT) {{
addRule(RelativeLayout.CENTER_IN_PARENT);
}});
RelativeLayout mainLayout = new RelativeLayout(this);
mainLayout.setBackgroundColor(Color.BLACK);
mainLayout.addView(mRenderSurfaceView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setId(View.generateViewId());
layout.addView(frameLayout, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

this.setContentView(
layout,
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT) {{
gravity = Gravity.CENTER;
}});
mainLayout.addView(frameLayout, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

// Adding a dummy View somehow fixes an issue with Android layout system where the layouts
// in the frame layout (where fragments are attached, see ActivityOverlay) are not properly
// displayed on the screen.
mainLayout.addView(new View(this), new LayoutParams(MATCH_PARENT, MATCH_PARENT));

setContentView(mainLayout, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
ActivityOverlay.initial(this, frameLayout.getId());
}

Expand Down
Loading