I want to show some data in a table inside a fragment once clicked a button in mainActivity. Since the table is wider, i change the orientation of the screen to landscape before dynamically creating the table in onCreateView function of the fragment. The table only shows half of the data as if it was opened in a portrait mode. Also if i switch to other apps in the phone, background color of the table in some parts get omitted. please help me.

Screen shot of the table

1

There are 1 best solutions below

0
At Na On

I solved the issue. The fragment screen was shown on a frame layout. so after loading the fragment i resized the Frame layout which was placed in the MainActivity by calling the below function from mainActivity in the fragments onCreate() function using ((MainActivity) getActivity()).reSize();

the below code is written in the mainActivity.

Public void reSize(){

    FrameLayout view = findViewById(R.id.frameSettings);
    if (null != view) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        MainActivity.this.getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        if(displayMetrics.widthPixels>displayMetrics.heightPixels) {
            view.getLayoutParams().width = displayMetrics.widthPixels;
            view.getLayoutParams().height = displayMetrics.heightPixels-270;
        }
        else{
            view.getLayoutParams().width = displayMetrics.widthPixels;
            view.getLayoutParams().height = displayMetrics.heightPixels;
        }
    }

}

Here i have reduced the height further by 270 in the landscape view because due to some issue some part of the framelayout was missing. don't know why. Hope it helps.