使用 android:configChanges=“orientation|keyboardHidden"时的选项卡小部件问题在网格视图中但适用于其他选项卡 [英] Tab Widget Issue when use android:configChanges="orientation|keyboardHidden" in Grid View but working for other Tab

查看:17
本文介绍了使用 android:configChanges=“orientation|keyboardHidden"时的选项卡小部件问题在网格视图中但适用于其他选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被我的问题困住了.事情是它是一个自定义选项卡小部件.在其中有多个标签像 Home - News - Abc - PQR .

I am stuck with my issue.Thing is that its a custom Tab Widget.In that have multiple tab like Home - News - Abc - PQR .

Activity 应该适用于纵向和横向两种方向.因此,每个选项卡都有 two xml 用于纵向存储在 layout-port/file.xml 和横向存储在 layout-land/file.xml

The Activity should be for both orientation like portrait and landscape. so for that each tab have two xml for portrait which is store at layout-port/file.xml and landscape which store at layout-land/file.xml

为了管理从纵向到横向的方向,我在每个活动中添加了 android:configChanges="orientation|keyboardHidden" 规则标签.

For manage orientation portrait to landscape i have added android:configChanges="orientation|keyboardHidden" rule tag in each activity.

  • TAB_SAMPLE.java 选项卡文件.
  • TAB_GROUP_ACTIVITY 每个选项卡组活动文件
  • file.java 任务文件
  • TAB_SAMPLE.java Tab file.
  • TAB_GROUP_ACTIVITY each Tab Group activity File
  • file.java Task file

毕竟我在这里遇到了问题:

如果我 addandroid:configChanges="orientation|keyboardHidden"rule tag in tab_sample 活动那么它的工作完美.喜欢管理不同的视图.港口到陆地和陆地到港口,但它在 Home.java 中不起作用.

If i addandroid:configChanges="orientation|keyboardHidden"rule tag in tab_sample activity then its working perfect. like manage different view. port to land and land to port but its not working in Home.java.

现在,如果我 删除 tab_sample 活动中的 android:configChanges="orientation|keyboardHidden" 规则标记,那么它适用于 Home 活动而不适用于 News.java

Now if i remove android:configChanges="orientation|keyboardHidden" rule tag in tab_sample activity then its working for Home activity not for News.java

意味着当我改变方向时,它保持相同的 xml 表单端口不从 layout-land 使用.从某种意义上说,它再次调用 OnCreate().

Mean when i change the orientation its keeping same xml form port not use from layout-land.in the sense its call OnCreate() again.

所以我发现可能是选项卡小部件中的问题.

更新

现在跟踪我的代码后,我发现主要问题在于网格视图活动,因为它唯一的活动不起作用.

Now after tracing my code i get that main issue is in grid view activity because its only activity which is not working.

Tab host 与 Grid View 之间存在问题.我不知道为什么它不采用 layout-land xml 文件.我发现 this 为同样的问题,但也没有重播该问题

Issue is between Tab host v/s Grid View. I don't know why its not taking layout-land xml file. i found this as same issue but no replay on that question also

详见manifestfile.xml我想在所有活动中保持纵向和横向.

see in Detail manifestfile.xml I want to maintain both portrait and landscape in all activity.

两个 XML 文件

请帮我解决这个问题.

推荐答案

Oooohhh 最后我得到了上述问题的解决方案.这是非常困难的.

Oooohhh Finally i got the solution for above issue. It's was very difficult.

为了保持横向到纵向的方向状态,反之亦然,我们通常在活动下添加 android:configChanges="keyboardHidden|orientation" 属性标签.

For maintain the state of orientation Landscape to portrait and vice-versa we generally adding android:configChanges="keyboardHidden|orientation" property tag under activity.

但这里 可能是 Tab_Group_Activity 的问题,因为我无法在 GridView 中维护状态.Grid_File.java只有一个 java 文件没有处理好所有其他文件的方向.

But here may be issue is Tab_Group_ Activity due to that i am not able to maintain state in GridView. Grid_File.java is Only single java file which was not handling the orientation rest of all other working perfectly.

现在如果我 TAB_SAMPLE.java 中删除 android:configChanges="keyboardHidden|orientation" 那么 它只处理 Grid_File.java 不是其他人.

Now if i remove android:configChanges="keyboardHidden|orientation" from TAB_SAMPLE.java then Its handling only Grid_File.java not others.

mean that was keeping same Layout XML in landscape also where i have two separate XML File.

这是我的解决方案:

我有 add android:configChanges="keyboardHidden|orientation"TAB_SAMPLE.java 以及实现onConfigurationChanged(Configuration newConfig)并设置网格的列数.像 gridView.setNumColumns(6);

I have add android:configChanges="keyboardHidden|orientation" in TAB_SAMPLE.java as well as implement onConfigurationChanged(Configuration newConfig) and set Number of column of grid. like gridView.setNumColumns(6);

@Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        // gridView.setSelection(index);
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {

            // Log.e("On Config Change", "LANDSCAPE");
            gridView.setNumColumns(6);

        } else
        {

            // Log.e("On Config Change", "PORTRAIT");
            gridView.setNumColumns(4);
        }
    }

通常我们在活动下添加 android:configChanges="keyboardHidden|orientation" 标记或 implementing onConfigurationChanged(Configuration newConfig) 但这里我都写了.

Generally we are adding either android:configChanges="keyboardHidden|orientation" tag under activity or implementing onConfigurationChanged(Configuration newConfig) but here i have written both.

这篇关于使用 android:configChanges=“orientation|keyboardHidden"时的选项卡小部件问题在网格视图中但适用于其他选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆