我已阅读此问题Set equal width of columns in table layout in Android
看到答案之后,确实列的大小相同,但是当我用EditText替换两个TextView时,不再出现相同的大小。我该如何解决?
这是修改后的代码:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:stretchColumns="*"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_calendar">
<TableRow android:layout_width="0dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity=""
android:text="table header1"
android:textSize="10dip"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="table header3"
android:textSize="10dip"
android:textStyle="bold" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="table header4"
android:textSize="10dip"
android:textStyle="bold" />
</TableRow>
</TableLayout>
答案 0 :(得分:0)
试试这个:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:stretchColumns="*"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TableRow android:layout_width="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity=""
android:text="table header1"
android:textSize="10dip"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="table header3"
android:textSize="10dip"
android:textStyle="bold" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="table header4"
android:textSize="10dip"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
</TableLayout>
答案 1 :(得分:0)
以下代码可帮助您实现所需目标。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:fitsSystemWindows="true"
>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/main"
>
<!-- name -->
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:drawable/dialog_holo_light_frame"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance=" android:attr/textAppearanceMedium"
android:text="name:"
android:textColor="@android:color/background_dark"
android:id="@+id/name"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceMedium"
android:text="user"
android:textColor="@android:color/background_dark"
android:id="@user"/>
</TableRow>
<!-- phone number -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/dialog_holo_light_frame"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceMedium"
android:text="phone number:"
android:textColor="@android:color/background_dark"
android:id="@+id/phonenumber"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceMedium"
android:text="1234567890"
android:textColor="@android:color/background_dark"
android:id="@+id/number"/>
</TableRow>
<!-- address -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/dialog_holo_light_frame"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="current address:"
android:textColor="@android:color/background_dark"
android:id="@+id/currentaddress"/>
<TextView
android:layout_height="wrap_content"
android:textAppearance="android:attr/textAppearanceMedium"
android:text="xyz"
android:textColor="@android:color/background_dark"
android:id="@+id/address"/>
</TableRow>
</TableLayout>
</ScrollView>