java表格布局问题
我在布置桌子时遇到了一些问题。当XML出现在屏幕上时,我编写XML的方式似乎并不像我认为的那样显示出来。我希望我的第一个tablerow的每一列大小相等,内容居中,但我得到的是前两列比后两列大
我的XML代码:
<TableLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:screenOrientation="portrait"
安卓:animateLayoutChanges="true"
tools:context=".SettingsActivity" >
<TableRow
安卓:id="@+id/tableRow1"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content" >
<TextView
安卓:id="@+id/lblIP"
安卓:layout_weight="1"
安卓:gravity="center"
安卓:text="@string/ip" />
<EditText
安卓:id="@+id/txtIP"
安卓:layout_weight="1"
安卓:gravity="center"
安卓:inputType="phone"
安卓:text="@string/ip_address" >
</EditText>
<TextView
安卓:id="@+id/lblPort"
安卓:layout_weight="1"
安卓:gravity="center"
安卓:text="@string/port" />
<EditText
安卓:id="@+id/txtPort"
安卓:layout_weight="1"
安卓:gravity="center"
安卓:inputType="number" />
</TableRow>
它的外观:
# 1 楼答案
尝试将
android:layout_width
属性设置为0dp
,并在子视图中将android:layout_weight
保持为1