Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a reference to an XML file from FrameLayout

Tags:

android

I need to get reference to separate XML file which is FrameLayout but I can't figure out how to do it, this code doesn't work:

FrameLayout desktopFrameLayout = (FrameLayout) findViewById(R.id.desktopsFramelayout);
desktopFrameLayout.setDrawingCacheEnabled(true);
desktopFrameLayout.buildDrawingCache();
Bitmap bitmap = desktopFrameLayout.getDrawingCache();
like image 815
Mickey Tin Avatar asked Mar 05 '13 10:03

Mickey Tin


People also ask

How do I insert one XML file into another Android?

Probably you will have to set within the include tag the properties that sets where it has to be placed: android:layout_above, android:layout_toLeftOf, etc... Use fill_parent instead. I pasted my code and I am working with honeycomb, thats why I was using match_parent. But it should work with fill_parent.

Is FrameLayout a ViewGroup?

Android Framelayout is a ViewGroup subclass which is used to specify the position of multiple views placed on the top of each other to represent a single view screen.

When can FrameLayout be used?

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

What is the XML element for adding a layout defined in another layout file?

To efficiently re-use complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout.


1 Answers

For that you have to use inflate view.

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.mylayout, null);

FrameLayout item = (FrameLayout ) view.findViewById(R.id.desktopsFramelayout);
like image 150
Chirag Avatar answered Oct 04 '22 22:10

Chirag