Android Question: Working With TableView/Text Under Icon
I'm looking to make a basic launcher for an application (basically a home screen that launches other activities). Using an absolute layout, I was able to come up with a rough idea of what I'm looking for. All of the "TextView" fields would be replaced with the name of the activity to be launched.
But I don't want to use an absolute layout, to avoid the obvious problems. I read on the forums that I could use a TableView, and each TableRow would add a row, and each ButtonImage would essentially add a column. The problem with that is I cannot seem to figure out how to get a TextView to appear underneath each image button, since that essentially inserts a new column into the table (so the image and text appear side-by-side instead of text under image).
Attached is my current XML for the example layout in absolute form. Any help would be IMMENSELY appreciated. :)
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget39"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageButton
android:id="@+id/news"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/news"
android:layout_x="87px"
android:layout_y="100px"
>
</ImageButton>
<ImageButton
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/phonebook"
android:layout_x="145px"
android:layout_y="100px"
>
</ImageButton>
<ImageButton
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/message"
android:layout_x="203px"
android:layout_y="100px"
>
</ImageButton>
<ImageButton
android:id="@+id/calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/planner"
android:layout_x="86px"
android:layout_y="179px"
>
</ImageButton>
<ImageButton
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/panic"
android:layout_x="145px"
android:layout_y="180px"
>
</ImageButton>
<ImageButton
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/exit"
android:layout_x="205px"
android:layout_y="180px"
>
</ImageButton>
<TextView
android:id="@+id/widget47"
android:layout_width="wrap_content"
andro开发者_开发问答id:layout_height="wrap_content"
android:text="TextView"
android:layout_x="80px"
android:layout_y="146px"
>
</TextView>
<TextView
android:id="@+id/widget48"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="142px"
android:layout_y="147px"
>
</TextView>
<TextView
android:id="@+id/widget49"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="201px"
android:layout_y="147px"
>
</TextView>
<TextView
android:id="@+id/widget50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="79px"
android:layout_y="227px"
>
</TextView>
<TextView
android:id="@+id/widget51"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_x="141px"
android:layout_y="228px"
>
</TextView>
<TextView
android:id="@+id/widget52"
android:layout_width="wrap_content"
android:layout_height="20px"
android:text="TextView"
android:layout_x="203px"
android:layout_y="228px"
>
</TextView>
</AbsoluteLayout>
You should insert a LinearLayout (or any other layout) as a row cell containing other elements.
The example code generates a TableLayout containing two TableRows, each containing three elements (as defined by the weightSum property). I used LinearLayouts as child elements (column cells) with vertical orientation, so the elements are positioned properly.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow
android:weightSum="3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
</TableRow>
<TableRow
android:weightSum="3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM AN ICON"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="APP NAME"
/>
</LinearLayout>
</TableRow>
</TableLayout>
And, as ryandlf pointed out, avoid using static dimensions if possible.
精彩评论