Does Android XML Layout's 'include' Tag Really Work?

Posted by Eric Burke on Stack Overflow See other posts from Stack Overflow or by Eric Burke
Published on 2010-04-13T17:10:36Z Indexed on 2012/09/30 15:38 UTC
Read the original article Hit count: 339

Filed under:
|

I am unable to override attributes when using <include> in my Android layout files. When I searched for bugs, I found Declined Issue 2863:

"include tag is broken (overriding layout params never works)"

Since Romain indicates this works in the test suites and his examples, I must be doing something wrong.

My project is organized like this:

res/layout
  buttons.xml

res/layout-land
  receipt.xml

res/layout-port
  receipt.xml

The buttons.xml contains something like this:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

  <Button .../>

  <Button .../>
</LinearLayout>

And the portrait and landscape receipt.xml files look something like:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

  ...

  <!-- Overridden attributes never work. Nor do attributes like
       the red background, which is specified here. -->
  <include
      android:id="@+id/buttons_override"
      android:background="#ff0000"
      android:layout_width="fill_parent"
      layout="@layout/buttons"/>

</LinearLayout>

What am I missing?

© Stack Overflow or respective owner

Related posts about android

Related posts about android-widget