使用 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" 时出现标签小部件问题在网格视图中但适用于其他选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被我的问题困住了.事实是它是一个自定义的 Tab Widget.在其中有多个标签如 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 应该用于两个方向,如纵向和横向.因此,对于每个选项卡都有 两个 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"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.

所以我发现可能是Tab Widget的问题.

更新

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

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

问题在 Tab 主机与网格视图之间.我不知道为什么它不采用 layout-land xml 文件.我发现这个同样的问题,但也没有重播那个问题

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.

现在如果我 remove android:configChanges="keyboardHidden|orientation"TAB_SAMPLE.java 那么它只处理 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.

这是我的解决方案:

我在TAB_SAMPLE.java 以及中添加了android:configChanges="keyboardHidden|orientation"实现 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天全站免登陆