The post below from Romain Guy might help, we will this information to the
docs:
__________________________________________________________________
There are three new features related to including layout:
<include />, <merge /> and ViewStub. Here is a quick description of
each of these features:
************* <include /> *************
You can include XML layouts from within other XML layouts. The syntax
is pretty simple:
<include layout="@layout/myLayoutId" />
Note that <include/> lets you override the android:layout_*,
android:id and android:visibility attributes. For instance:
<include
layout="@layout/include_button"
android:id="@+id/included_button_overriden"
android:layout_width="237dip"
android:layout_height="123dip" />
If you don't specify anything, the attributes from the included file
will be used.
************* ViewStub *************
This view lets you lazily include other XML layouts inside your
applications. ViewStub can be used if you have very complex layout
that contains many Views that you rarely use (if you have parts of
your layouts with a GONE visibility, you have good candidates.)
It's easy to use:
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/mySubTree"
android:layout_width="120dip"
android:layout_height="40dip" />
The attribute android:layout designates the layout that you want to
inflate. The attribtue android:inflatedId is optional and can be used
to override the android:id declared in the included layout.
A ViewStub is in visibility=GONE by default, has a size of 0 pixels,
doesn't draw and doesn't measure itself. However, when you call either
setVisibility(VISIBLE) or inflate(), the ViewStub removes itself from
its parent, inflates your layout and adds the layout in the parent at
the position the ViewStub previously occupied. The recommended way of
suing ViewStub is the following:
ViewStub stub = (ViewStub) findViewById(R.id.stub);
View inflated = stub.inflate();
Calling inflate() gives you back a reference to the inflated View.
This avoids performing an extra call to findViewById(). You should
avoid keeping a reference to the ViewStub in a class member since this
will cause the ViewStub to "leak" as soon as you inflate() it.
************* <merge /> *************
This tag is useful especially if you create custom views whose content
you want to inflate from XML. A XML layout needs a root tag and its
often end up being an unnecessary extra level in the view hierarchy.
By using <merge /> you can skip this extra level. This feature is very
useful to improve memory and performance in ListView items for
instance.
Here is an example. Imagine an application whose CustomView inflates
its content from XML in its constructor. The XML content used to be
the following:
<FrameLayout>
<ViewStub/>
<ViewStub/>
</FrameLayout>
Every message view would thus end up with only one child, a
FrameLayout, used only to satisfy XML syntax constraints. With merge
the XML now looks like this:
<merge>
<ViewStub />
<ViewStub />
</merge>
After inflation, the CustomView has two children, the two ViewStub. In
summary, the <merge /> tag just means "ignore me, add my children to
my parent." This tag can be used in an XML layout included with
<include /> from another XML layout.
Limitations:
- <merge /> must be the root tag
- When you call LayoutInflater.inflate() you *must* pass a root and,
if specified, attachToRoot must be true
- A ViewStub won't be able to inflate an XML layout that contains a
<merge />
If you fail to comply you will receive an exception during the
inflation.
2008/9/4 Jerome O'Neil <[EMAIL PROTECTED]>
>
> I have a couple of widgets that I would like to appear on each
> Activity within my application. I've been trying to set up an
> AbstractHandler that extends Activity that implements these common
> bits of code, and then have each of my Activity classes extend that,
> and then have those classes implement just the components that are
> important to them. That's pretty basic stuff.
>
> My problem is that when I set up the layout in XML in the concrete
> class, it over writes the layout in the abstract class, and I then
> lose the common widgets.
>
> A general sketch of the problem.
>
> public abstract class Foo extends Activity{
>
> public void onCreate(Bundle bundle){
> super.onCreate(bundle);
>
> // I want these buttons inherited by every Activity in my
> application.
> setContentView(R.layout.abstractbuttons);
> }
>
> }
>
>
>
> public class Bar extends Foo{
>
> public void onCreate(Bundle bundle){
> super.onCreate(bundle);
>
> // These buttons are specific to this Activity, but by setting
> the content view differently, I lose the
> // Buttons in Foo.
> setContentView(R.layout.specificbuttons);
> }
> }
>
> So I guess what I want is a way to merge to XML layouts.
>
> Is that possible?
>
> Many thanks,
>
> -J
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---