Archive for the ‘Mobile Development’ Category

Android LinearLayout tag not stacking elements

Thursday, May 6th, 2010

This is really more of a reference for myself than anything else.  Point being I just spent about half an hour trying to figure out why my TextViews were not showing up in my LinearLayout for my Android application.  What I was getting was the top level TextView but none of the others below it.  As I moved them around in their order I realized that they were there, but falling behind the TextView on top.  So, clearly, the issue is that they are layering instead of stacking.

Just to make sure we’re all on the same page in resolving this issue (which is really not an issue at all) we’re working on a layout XML file for an Android application.  So if you’re using the built-in Eclipse Android plugin you will have a main.xml file by default in the res/layout directory.  If you delete the XML from this file and add a new LinearLayout from the layout perspective, and then add some TextViews or whatever, you’ll notice that only the top one shows.

So for example.

Does not work

<LinearLayout 	android:id="@+id/LinearLayout01"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			xmlns:android="http://schemas.android.com/apk/res/android"
			android:background="@android:color/black">

</LinearLayout>

and…

Does work

<LinearLayout 	android:id="@+id/LinearLayout01"
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			xmlns:android="http://schemas.android.com/apk/res/android"
			android:background="@android:color/black"
			android:orientation="vertical">

</LinearLayout>

For whatever reason, when you add a LinearLayout like this it does not include the ‘android:orientation=”vertical | horizontal”‘ attribute.  Apparently this is a pretty important attribute.  This determines if the assets stack horizontally or vertically.  And if not specified no error is thrown, instead it just seems to layer, or possibly just show the top asset.  Doesn’t really matter as far as I see it.  For those of us who have no idea what we’re doing it should seriously throw an error or something.

Device does not show up in Eclipse ‘Android Device Chooser’

Thursday, May 6th, 2010

This is just a quick note on how to make sure your device shows up in the device listing when debugging an Android app in Eclipse. I spent some time trying to figure this out since I had the plugins all installed and the app ran good in the Emulator, but my device just wouldn’t show up in the device list when choosing to debug manually. I found the solution, of course, in the docs.

So if you’re having this problem you should make sure that your device is set up for debugging. I’m running the Droid Incredible, so you may need to take slightly different steps to accomplish this than what I layout here.

  1. On the home screen of your device choose Menu > Settings > Applications > Development.
  2. Make sure that ‘USB debugging’ is checked. I would also suggest checking the ‘Stay awake’ option as well so you don’t have to keep waking your phone up during debugging.

If the rest of your debug settings are correct your device should show up.  At least for me this was the solution.