Will I be sorry for semi-decoupling my Layout from my Activity?

70 Views Asked by At

In Droidio (Android Studio) at least (I don't know about Eclipse, but it's probably the case with ItelliJ Idea, too, as Droidio is based on it), when you create a new Activity, a corresponding Layout file is also created. By default, it is tightly coupled to the Activity by means of two properties, namely the "xmlns:tools" and "tools:context" lines below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="4dip"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="hhs.app.PlatypusActivity">

This seems odd/unnecessary to me, as the Activity is also automagically bound to the corresponding Layout in the onCreate() method of its *.java file this way:

setContentView(R.layout.activity_platypus);

Is this a case of simply being "thorough" (wearing belts and suspenders), or is it a case of too-tight coupling? The explicit wiring on the Layout side (to the Controller/Activity) has a bit of a code smell to me. If I remove the two questionable lines from the xml ( "xmlns:tools" and "tools:context") it still works fine, so I don't understand what purpose they serve.

Will I live to rue the millisecond I semi-decoupled the Activity/Layout (Controller/View)?

0

There are 0 best solutions below