Fragment Overlapping Problem

Asked 2 years ago, Updated 2 years ago, 58 views

Here's an Android question.

I wrote an expandable list view.

If you press each menu, you can also display a regular fragment and a fragment web view.

If you display a regular fragment and then display a fragment web view, the web view is displayed hidden behind the regular fragment.

I want to solve the problem of not being able to see the web view below due to overlapping fragments even though the execution is going well.

MainActivity.java

public class MainActivity extends AppCompatActivity {


// It's a fragment web view of the main screen
    static public class MyWebViewFragment extends Fragment {
        private WebView webView;



        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

            webView = new WebView(getActivity());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebChromeClient(new WebChromeClient());
            webView.setWebViewClient(new WebViewClient());
            webView.loadUrl("http:///...~");


            return webView;


        }
    }



...



// First menu, regular fragment
 menu01Activity fragment = new menu01Activity();
                                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                                fragmentTransaction.replace(R.id.myweb_fragment, fragment);
                                fragmentTransaction.commit();





//Second menu, fragment web view
 MyWebViewFragment fragment2 = (MyWebViewFragment)getFragmentManager().findFragmentById(R.id.myweb_fragment);
                                WebView webView = fragment2.webView;

                                webView.getSettings().setJavaScriptEnabled(true);
                                webView.loadUrl("http://m.daum.net");





I know that if you want to float the fragment on top of the fragment, you can use replace instead of add In this case, we're going to put a fragment web view on the fragment, so what do we do? I don't know

fragment webview android

2022-09-21 22:59

1 Answers

If overlapping is a problem (=a phenomenon that is obscured by other fragments when the web view should be visible), you can solve it using the replace(), remove() function.

If you click on the first menu in the code you uploaded, you will be able to call the replace() function, but if you click on the second menu, you will be only processing the web page movement to http://m.daum.net. Therefore, it is true that the web view is not visible with the current code.

If you want to make certain fragments visible when you click on the menu, you need to add, delete, and replace them here. Each corresponding API is add(), remove(), and replace(). Call the replace() function as you would if you clicked on the first menu.

Alternatively, you can remove the fragment (on the first menu) that covers the top. Please use the appropriate method for the UI you are implementing.

Refer to the link below under Performing a fragment transaction for related information.


2022-09-21 22:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.