DecorView子框架布局在设备上有所不同



我在github.com/bk138/LibSlideMenu 中使用类似的库

它在HTC device(ICS)Nexus 7(ICS)以及其它Gingerbread器件上都能很好地工作。

但有些设备像Motorola atrix和另一个HTC设备。

所以我检查了代码。

View view  = act.findViewById(android.R.id.content);
Utils.Log("<SlideMenu> : VIEW : "+view);        
ViewParent viewParent = view.getParent();
Utils.Log("<SlideMenu> : VIEW : "+viewParent);  
LinearLayout linearLayout = (LinearLayout) viewParent;
Utils.Log("<SlideMenu> : VIEW : "+linearLayout);
content = linearLayout;

在这里,第一件事是在所有设备上返回FrameLayout

但第二件事是在ICS设备和其他HTC 2.3设备上返回LinearLayout,一些设备返回DecorView

我参考这篇文章:装饰视图儿童框架布局

他们说我使用NoTitleBar有问题,所以我显示标题栏,但它不起作用。

此外,尽管我添加了NoTitleBar属性,但有些设备确实工作得很好。

这真的很令人沮丧,因为设备有不同的结果。有人知道吗?

请帮忙:D提前谢谢。

我相信我们可以确定关于PhoneWindow$DecorView的一些事情(或者至少和为android开发的一样确定)。

首先,DecorView扩展了FrameLayout,因此,我们可以放心地将其转换为父类ViewGroup。也就是说,第二,我们也可以确信DecorView包含父类View(否则它将是一个相当无聊的ViewGroup,不是吗)。

这让我得出结论,应该从上到下攻击这个问题,而不是像有问题的库代码所尝试的那样从下到上攻击。

例如:

ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
View oldScreen = decorView.getChildAt(0);
decorView.removeViewAt(0);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
SlidingPanel slidingPanel = (SlidingPanel) inflater.inflate(R.layout.screen_slider, null);
((ViewGroup) slidingPanel.findViewById(R.id.anterior)).addView(oldScreen);
decorView.addView(slidingPanel, 0);

我最近实现了一个类似的基本SlidingPanel小部件,并按照上面的说明使用它。你可以在这里找到它和更多的用法示例https://github.com/mubeta06/android/tree/master/SlidingFrame.

Android SDK文档中没有任何内容指定android.R.id.content的布局类型,更不用说它的父级了。这可能会因安卓操作系统的发布、设备制造商的更改或修改ROM而有所不同。大多数SDK开发人员甚至不应该接触android.R.id.content的父级;任何人都不应该假设它有任何具体的东西。

https://github.com/bk138/LibSlideMenu/commit/9b9ae22c8e463559324e377f6e89a430dd4fd7ca希望能解决这个问题。

检查我为LibSlideMenu做的这个链接:

private static ViewGroup parent;

将所有FrameLayout.LayoutParams转换为

LayoutParams  parent = (ViewGroup) act.getWindow().getDecorView();

最新更新