Graeme
Graeme

Reputation: 25864

<include> tag isn't accurately displaying it's content

I have a layout menu which contains this:

<RelativeLayout android:id="@+id/computersMenu"
                android:layout_width="50dp"
                android:layout_height="50dp">
        <include        layout="@layout/component_add_button"
                        android:id="@+id/imagebutton_add_client"/>  
</RelativeLayout>

component_add_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<ImageView  xmlns:android="http://schemas.android.com/apk/res/android"  
            android:src="@drawable/ic_menu_add"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"/>    

Looking at the preview (EDIT: I mean the "Graphical Layout" tab of the xml editor in eclipse which uses the same rendering engine as all devices AFAIK) of component_add_button.xml you can see the image. Great. On the page which is including it it isn't displaying (although it does give you a selectable space where the image should be).

This seems like a really simple example that "should just work". The include tag has always seemed really flaky to me - I'm wondering if I'm missing something in terms of how it actually works...?

Upvotes: 1

Views: 115

Answers (2)

Moog
Moog

Reputation: 10193

As your answer states, the eclipse preview does not display included layouts.

The simplest way to avoid doubt or mistakes in markup when "including" layout's is to design in the original layout then right click the view you wish to extract and select Extract include... from the menu

Upvotes: 1

Graeme
Graeme

Reputation: 25864

On a device this functionality worked fine. This seems like a bug in the "Graphical Layout" tab of the layout xml editor shipped with android-sdk.

Upvotes: 0

Related Questions