片段屏幕在更改方向和背景颜色时切开,切换到其他应用

发布于 2025-02-09 06:14:58 字数 266 浏览 4 评论 0原文

我想在片段内的表中显示一些数据,一旦单击MainActivity,就单击了按钮。由于表更宽,因此我将屏幕的方向更改为景观,然后在片段的OnCreateview功能中动态创建表。该表仅显示一半数据,就好像是在肖像模式下打开的一样。另外,如果我切换到手机中的其他应用程序,则省略了某些零件的背景颜色。请帮我。

表的屏幕截图

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫之都 2025-02-16 06:14:58

我解决了这个问题。片段屏幕显示在框架布局上。因此,在加载片段后,我通过调用以下功能从mainActivity中放置的帧布局,使用片段中的mainActivity使用以下函数。
((MainActivity)getActivity())。resize();

以下代码以主攻击性编写。

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;
        }
    }

}

在这里,我在景观视图中将高度进一步降低了270,因为由于缺少Framelayout的某些问题。不知道为什么。希望它有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文