Tag: layout technique
Layout technique: Center a TextView with a Button left and right
by Martin on Oct.29, 2009, under layout technique
While working on an application which should look similar to an iPhone application, I have to create a bar at the top where I have a back and a forward button (each on one side) and a dynamic text centered in the middle between them.
To get this done, I searched quite a lot and got it finally to work.
The surrounding layout should be the RelativeLayout with two Buttons (in my case I used ImageViews) and a TextView.
(continue reading…)
Layout technique: Static elements below ScrollView
by Martin on Apr.07, 2009, under layout technique
Did you ever want to know how to place an element below a ScrollView which will normally fill the whole screen?
This is only possible by a little trick: Using margins.
The ScrollView must have positive layout_marginBottom, and the element below the ScrollView must have negative layout_marginTop.
(continue reading…)
Display borders in TableLayout
by Martin on Mar.20, 2009, under how to
As the developer guide says that table border lines are not displayed there is only a dirty fix for this problem:
Give the TableLayout a background color, give the TableRow another background color and set margin to the TableRow. The amount of the margin is the amount of the “border”. Same for each View in the TableRow.
A “dirty” sample:
1 2 3 4 5 6 7 8 | <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="*" android:background="#ff0000"> <TableRow android:background="#00ff00" android:layout_margin="2dip"> <Button android:id="@+id/button" android:text="+" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:text="@string/label" android:background="#0000ff" android:layout_margin="2dip"/> <TextView android:id="@+id/amount" android:background="#0000ff" android:layout_margin="2dip"/> </TableRow> |
Source: My answer on anddev.org forum
TableLayout supports column span
by Martin on Mar.13, 2009, under how to
While working on a little game to learn more about Intents, Activity life cycle and other stuff, I used the TableLayout for the first time. I realized that the auto-completion missed the attribute android:layout_span which is referred by the R.attr. The same with android:stretchColumns. As I read some minutes ago, some people still think column span is not possible – so I decided to publish a sample to prove them wrong.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <!-- snipped --> <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="*"> <TableRow> <TextView android:id="@+id/info" android:layout_span="3" android:text="@string/info" android:layout_gravity="center_horizontal" /> </TableRow> <TableRow> <Button android:id="@+id/button_add" android:text="+" /> <TextView android:text="@string/label" /> <TextView android:id="@+id/amount" /> </TableRow> <!-- snipped --> </TableLayout> <!-- snipped --> |
If the auto-completion leaves out an attribute, there can be more attributes being unsupported, so always use the API as cross reference!
First list application
by Martin on Feb.28, 2009, under tutorial
Yesterday we started a tutorial we found on the youtube channel of androiddevelopers. The intent of this tutorial is to create an application that shows all contacts by name. You also should be able to click on the name and the phone will start a call to this contact.
The tutorial itself is more than a year old, has some failures and some stuff isn’t available in the same way the tutorial shows. We will show you what you have to do to be successfully program this little android application and we will show you some useful layout improvements.
(continue reading…)