Android applications keep resources in the res directory under three directores: drawable-hdpi, drawable-mdpi, and drawable-ldpi. The directories are to assist with the different screen sizes. As long as you put correctly sized images in the correct directory your application will look fine no matter what screen size is being used.
If your application has a lot of images this can be a pain resizing all those images, so I wrote a utility that would do it. I thought I would share the source here:
ImageScaler.java
Feel free to use it, I'm open to answering any questions about it, or even making changes for good suggestions.
Monday, May 30, 2011
Android Adding a View Below a ListView
In Android development, adding a View below a ListView is more challenging than one might think. When I ran into this issue, I did what anyone would do: started Googling for a solution. There are a number of close solutions out there, but nothing that really solves the problem. So I thought I would write up a simple solution here to help out the community.
Starting with a simple example:
This will give us the desired View below a ListView.

However this is cheating, because if we add one more item to the list the TextView disappears.

This was my motivation to write this blog entry. This all seems pretty straight forward, but ListView is allowed to grow enough to cover up the TextView. I encountered a lot of solutions out there, but wasn't happy with any of them. I played around with weights until I realized that I could give the ListView a weight of 1 and leaving the TextView with the default (0).
I ended up with my desired result:

a View below a ListView. I hope this helps.
Starting with a simple example:
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout android="http://schemas.android.com/apk/res/android"
orientation="vertical"
layout_width="fill_parent"
layout_height="fill_parent">
<listview id="@+id/android:list"
layout_width="fill_parent"
layout_height="wrap_content"
entries="@array/numbers"
layout_margin="8dp" />
<textview
layout_width="fill_parent"
layout_height="wrap_content"
text="@string/hello"/>
</linearlayout>
This will give us the desired View below a ListView.

However this is cheating, because if we add one more item to the list the TextView disappears.

This was my motivation to write this blog entry. This all seems pretty straight forward, but ListView is allowed to grow enough to cover up the TextView. I encountered a lot of solutions out there, but wasn't happy with any of them. I played around with weights until I realized that I could give the ListView a weight of 1 and leaving the TextView with the default (0).
<!--?xml version="1.0" encoding="utf-8"?-->
<linearlayout android="http://schemas.android.com/apk/res/android"
orientation="vertical"
layout_width="fill_parent"
layout_height="fill_parent">
<listview id="@+id/android:list"
layout_width="fill_parent"
layout_height="wrap_content"
layout_weight="1"
entries="@array/numbers"
layout_margin="8dp" />
<textview
layout_width="fill_parent"
layout_height="wrap_content"
text="@string/hello"/>
</linearlayout>
I ended up with my desired result:

a View below a ListView. I hope this helps.
Weather Alarm
Weather Alarm Android App
Announcing my latest Android App, an alarm clock that also tells you the weather. That's right, an alarm clock that tells you the weather! It allows multiple alarms that can repeat day to day, or skip days. You customize your location or it will find you location for you, in case you don't know where you are.
I'm a huge Seinfeld fan. I watched Seinfeld when it was on the air, then I watched the re-runs so much I got sick of it, I had every show memorized. Hear lately I've returned for another round, and I appreciate the show even more. If you're a fan as well, you must remember the Bizarro Jerry episode. From Superman's bizarro world, where everything is backwards, or really the opposite they created a slight spoof on that where Elaine met a bizarro Jerry named Kevin. There was also a bizarro Kramer named Feldman. Kramer always comes up with ridiculous ideas and implements them almost immediately, well Feldman came up with an idea of an alarm clock that also tells you the weather. The opposite being Feldman came up with a good idea, but never did anything about it. So this was the birth of the weather alarm app.
I tried to pick up weather feeds, and that still might be the way to go, I've seen other apps do that, but I could get it to work consistently enough to suit me. I knew how to get the weather from Google, so I converted that feed into text and ran it through Android's built in text-to-speech converter.
Since it was my first app, I didn't want to charge anything, but I was interested in how to get those ads in an app. It turns out it's pretty easy, so I added ads to it. Feel free to click on those ads as much as possible.
I hope you enjoy getting the weather when you first wake up.
Sunday, October 10, 2010
Grand Opening
Welcome to heathb.com. I'm considering this the grand opening. Setting up a website is really rather easy, but I've had a lot of difficulty. I was running benheath.org, and I liked that url really well. My hosting site just quit, no warning, no nothing. So that's a little frustrating. I considered running the site out of my basement, but I could only use port numbers over 1024, the firewall at my office wouldn't allow me to access my own site, which is important to me. In fact that's the site's main purpose is to provide a place for me to dump files that I would like to access later. There are other ways to do this, but this is my favorite. Plus I just enjoy having a site, even if it looks funny, or I don't quite have everything setup. Before benheath.org, I was jumping from host to host for websites. So why's it so hard? Well it isn't hard, but I have my problems because I'm particular, and I want too many things. I'm getting my requirements under control, and I 'm enjoying this site. I love webdesign and I love tweaking this site. I hope I can provide something useful to someone. That's my goal.
Friday, November 28, 2008
iMac Too Bright
I love my new 24" iMac. It's fast and I love the big screen. I do have a problem though, which is the screen is incredibly bright. Do a quick Google search and you get brilliant answers like "put on sunglasses", or "turn on more lights in your work area". Another suggestion, which isn't what I wanted, but not too bad either is Ctrl-Alt-Command-8 which reverses all of the colors. The best solution seems to be shades. Which lets you adjust the brightness of the screen. I don't know why Apple doesn't let you do this in the first place, but shades provides the answer.
Friday, October 10, 2008
Use Firebug for browsing
I wanted to write a little something about how to use Firebug to enhance you web browsing. Basically if you don't like how a page is formatted, bring you firebug, click the HTML tab and then click on "Inspect". Now you can select the section of the web page you don't like the formatting of and find the html. To the right there will be a box that has the styles for the page. You can turn off or modify styles until you get the page looking how you want.
I always set my default font in Firefox so when I turn off a font style it usually reverts to the font and font size that I like. Then it's usually a matter of making the text wider. I like the text to fill up the page, so I go in a hunt for width attributes. I change a hard coded number to a percentage, like 80% or whatever I think looks good. Then if I don't like the color I modify that.
There are many things you can do and to me this helps you learn about web programming. In fact if I need to change the layout of a page I usually get it close and then hit Firebug to correct it until it's right. At preset, I don't think there's a way to save these changes (that would be sweet!), but it's still pretty useful.
You can also use Grease Monkey to enhance a page that you visit often. I find that I don't use Grease Monkey as much. I think because it's harder to use, you have to actually code. It would be nice, and perhaps I should look into this, to save what you've done in Firebug to Grease Monkey. Wow that would be cool!
This gives me an idea of something to work on.
I always set my default font in Firefox so when I turn off a font style it usually reverts to the font and font size that I like. Then it's usually a matter of making the text wider. I like the text to fill up the page, so I go in a hunt for width attributes. I change a hard coded number to a percentage, like 80% or whatever I think looks good. Then if I don't like the color I modify that.
There are many things you can do and to me this helps you learn about web programming. In fact if I need to change the layout of a page I usually get it close and then hit Firebug to correct it until it's right. At preset, I don't think there's a way to save these changes (that would be sweet!), but it's still pretty useful.
You can also use Grease Monkey to enhance a page that you visit often. I find that I don't use Grease Monkey as much. I think because it's harder to use, you have to actually code. It would be nice, and perhaps I should look into this, to save what you've done in Firebug to Grease Monkey. Wow that would be cool!
This gives me an idea of something to work on.
Tuesday, October 7, 2008
Blogging Gap
Wow I can't believe such a huge gap in my blogging. I suppose I wasn't as interested in it as I thought. I plan to start picking it up again, but we'll see. This isn't much of a post, but I wanted to put something out to start up again. Whew! I guess that wasn't too hard.
Subscribe to:
Comments (Atom)