<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="4" >
<TextView
android:id="@+id/lblIP"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/ip" />
<EditText
android:id="@+id/txtIP"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:inputType="phone"
android:text="@string/ip_address" >
</EditText>
<TextView
android:id="@+id/lblPort"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="@string/port" />
<EditText
android:id="@+id/txtPort"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:inputType="number" />
</TableRow>
TableLayout problems
-
30-09-2022 - |
Question
I'm having some problems aranging a tablelayout. The way i've written the XML doesnt seem to show as i think it should when it appears on the screen. I want each column of my first tablerow to be equal in size, with its contents centered but what i am getting is the first 2 column bigger than the second two.
My XML code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:screenOrientation="portrait"
android:animateLayoutChanges="true"
tools:context=".SettingsActivity" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/lblIP"
android:layout_weight="1"
android:gravity="center"
android:text="@string/ip" />
<EditText
android:id="@+id/txtIP"
android:layout_weight="1"
android:gravity="center"
android:inputType="phone"
android:text="@string/ip_address" >
</EditText>
<TextView
android:id="@+id/lblPort"
android:layout_weight="1"
android:gravity="center"
android:text="@string/port" />
<EditText
android:id="@+id/txtPort"
android:layout_weight="1"
android:gravity="center"
android:inputType="number" />
</TableRow>
How it appears:
Solution
OTHER TIPS
try to set the android:layout_width
attribute to 0dp
and keep the android:layout_weight
as 1
on the child views
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow