Android Development – XML-Based Layout Requirements
filed in Programming on Aug.16, 2010
Just a quick note to anyone like me experimenting with Android development. Take this XML snippet:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/btn01"
android:text="@string/goButton"
/>
</LinearLayout>
I hit compile, it built fine and went to the simulator, but the app crashed right when it ran. Apparently, LinearLayout requires the layout_height and layout_width to be defined, as such:
<Button
android:id="@+id/btn01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/goButton"
/>
I’ll continue to post these idiot moments as I find them…

Leave a Reply