meeDamian
meeDamian

Reputation: 1164

layout_margin not inherited from included ImageView

So I have two files:

where_include_happens.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hours"
    android:layout_height="wrap_content"
    android:layout_width="60dp">

    <include android:id="@+id/some_id" 
        layout="@layout/whats_included"
        android:layout_width="18dp"
        android:layout_height="18dp" />

</RelativeLayout>

And

whats_included.xml

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="6dp"
    android:contentDescription="@string/some_description"
    android:src="@drawable/some_awesome_drawable"  />

My problem is that each one of those elements should have android:layout_margin="6dp" parameter, but it seems to be ignored by include :(. Only thing in documentation, that I find related is:

Caution: If you want to override layout attributes using the tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.

My question is:

Is there something I'm not seeing, or am I condemned to write android:layout_margin="6dp" in every single include in my project?

Upvotes: 1

Views: 187

Answers (1)

Alexander
Alexander

Reputation: 48272

Since your include.xml consists of a single ImageView only you can, instead of using include directive, define a style for your ImageView and apply that style as needed.

Upvotes: 3

Related Questions