Seongeun  So
Seongeun So

Reputation: 817

DecorView child framelayout is different at devices

I use the library similar in github.com/bk138/LibSlideMenu

And it worked very well in HTC device(ICS) and Nexus 7(ICS), and other Gingerbread device.

But some devices like Motorola atrix and another HTC device.

So I checked the code.

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;

In here, first thing returns FrameLayout on all of devices.

But second thing returns LinearLayout on ICS device and other HTC 2.3 device, and some devices return DecorView.

I refer this post : DecorView Child FrameLayout

They said it is problem that I use NoTitleBar, so I show title bar but it doesn't work.

Also, Even though I added NoTitleBar attribute, some devices do work very well.

It's really frustrating since devices have different result. Does anyone know about it?

Please Help :D Thanks in advance.

Upvotes: 3

Views: 4384

Answers (4)

Mat Baker
Mat Baker

Reputation: 134

I believe we can be certain of a few things regarding PhoneWindow$DecorView (or at least as certain as one developing for android can be).

Firstly, DecorView extends FrameLayout and, therefore, we can be confident in casting it to parent class ViewGroup. That said, secondly, we can also be confident that the DecorView contains parent class View(s) (otherwise it would be a rather boring ViewGroup wouldn't it).

This leads me to the conclusion that this problem should be attacked from the top down rather than bottom up as the library code in question is attempting.

For example something like this:

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

I have recently implemented a similar rudimentary SlidingPanel widget and make use of it as per above. You can find it and further example usage here https://github.com/mubeta06/android/tree/master/SlidingFrame.

Upvotes: 6

yogikalwar
yogikalwar

Reputation: 81

Check this link I did for LibSlideMenu:

private static ViewGroup parent;

Converted all FrameLayout.LayoutParams to

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

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006964

There is nothing in the Android SDK documentation that specifies the layout type of android.R.id.content, let alone its parent. This can vary, either by Android OS release, device manufacturer alterations, or modded ROM changes. Most SDK developers should not even be touching the parent of android.R.id.content; none should be assuming anything specific about it.

Upvotes: 1

Related Questions