I have read this question Set equal width of columns in table layout in 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. 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>
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.