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.
Asked
Active
Viewed 69 times
-1
-
I have solved the issue of background color of the table being missing. I have used a ShapeDrawable to fille and draw border around the textview inside the table. but Using setBackgroundColor() method of Textview solves the issue. – At Na Jun 22 '22 at 17:13
1 Answers
0
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.

At Na
- 1
- 1