android - How to get a TableLayout with 2 columns of equal width -
why doesn't table have equal column widths? here's complete layout: first table, 2 buttons in linearlayout outside of table, divided equally.
<?xml version="1.0" encoding="utf-8"?> <scrollview 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" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <tablelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="4dp" > <tablerow android:layout_margintop="2dp" android:gravity="center_vertical" > <textview style="@style/label.plain" android:layout_width="match_parent" android:text="@string/caption" /> <edittext android:background="#00ff00" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="@dimen/button_height" android:inputtype="numberdecimal" android:selectallonfocus="true" android:textsize="@dimen/spinner_text" /> </tablerow> </tablelayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="2dp" android:layout_marginbottom="3dp" android:gravity="center_vertical" android:orientation="horizontal" > <button android:id="@+id/btnok" style="@style/button.plain.fill" android:layout_weight="1" android:text="@string/als_ok" /> <button android:id="@+id/btnclose" style="@style/button.plain.fill" android:layout_weight="1" android:text="@string/cancel" /> </linearlayout> </linearlayout> </scrollview>
and here's how looks (one column painted visibility):
i use linear layout here, want understand logic behind tablelayout
.
you can acquire in different ways,
like using
android:stretchcolumns="*"
in tablelayout or
android:weightsum="1"
in tablerow ,
android:layout_width="0dp" android:layout_height="wrap_content"
in , views in tablerow.
here example
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <tablelayout android:id="@+id/tbltop10list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerinparent="true" android:layout_margintop="23dp" android:stretchcolumns="*" > <tablerow android:id="@+id/tablerow1" android:layout_width="match_parent" android:layout_height="wrap_content" android:weightsum="1" > <textview android:id="@+id/tvtopname" android:layout_width="0dp" android:layout_height="wrap_content" android:paddingleft="8dp" android:text="hello there" android:textcolor="#fff000" android:layout_column="0" /> <textview android:id="@+id/tvtopnumber" android:paddingleft="4dp" android:layout_width="0dp" android:layout_height="wrap_content" android:textcolor="#fff000" android:text="hello there " android:layout_column="1" /> </tablerow> </tablelayout> </linearlayout>
** more info table layout , it's property please check nice article
http://www.informit.com/articles/article.aspx?p=2007353&seqnum=7