I often wish I could specify the placement of views — buttons, text views, etc. — within a screen by percentages: “Put one button 33% of the screen height from the top, and the other button 67% of the screen height from the top. In other words, two buttons evenly spaced vertically.” Alas, the Android SDK does not make it quite that easy. (As far as I know anyway; if you know better please comment and let me know!)

I recently discovered how the Space view element, combined with the layout_weight attribute, can help accomplish this layout goal without too…

Any app that doesn’t run solely in the background is going to need to interact with the user. Fortunately, the Android SDK provides a huge variety of methods to help an app recognize when a user does something, and respond appropriately. These are event handlers — a user click, tap, swipe, shake, etc. is an event, and these methods handle those events by giving the programmer a place to add the instructions describing how the app should respond.

Let’s start with a Button. You can add a Button element in your xml layout, and get a corresponding button object in…

Charles Drews

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store