[英]Set equal width of columns in table layout in Android with different components
I have read this question Set equal width of columns in table layout in Android 我已阅读此问题在Android中的表格布局中设置相等的列宽
After seeing the answer, it is true that the columns take the same sizes, but when I replace two TextView with an EditText, the same sizes do not appear anymore. 看到答案之后,确实列的大小相同,但是当我用EditText替换两个TextView时,不再出现相同的大小。 How can I solve that? 我怎么解决这个问题?
This is the modified code: 这是修改后的代码:
<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>
try this: 尝试这个:
<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>
The code below might help you achieve what you want. 下面的代码可以帮助您实现您想要的目标。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.