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:
尝试将android:layout_width
属性设置为0dp
并将子视图中的android:layout_weight
保持为1
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.