How To Use Weights To Arrange Gridview Items Programmatically With Tablelayout
I am working on a Suduko solver app. I want the layout to have 9x9 TextView in 9 Gridviews. I want to put below them two buttons (Solve, clear). I have made it but it does not work
Solution 1:
Here's a trick: For a completely uniform table or grid, you don't need TableView or GridView at all. Just put everything inside LinearLayout with size=0 and layoutWeight=1. That size=0 seems counter-intuitive, but combined with the layoutWeight=1, it has the effect of giving all child widgets the exact same size, regardless of their contents.
So do something like this:
<!-- Outer container; a vertical layout that fills the screen --><LinearLayoutandroid:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent" ><!-- first row --><LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1"><!-- contents of the first row --><!-- first item in first row --><Viewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1" /><!-- second item in first row --><Viewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1" /><!-- third item in first row --><Viewandroid:layout_width="0dp"android:layout_height="fill_parent"android:layout_weight="1" /></LinearLayout><!-- second row --><LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1"><!-- contents of the second row. --><!-- etc --></LinearLayout><!-- third row --><LinearLayoutandroid:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="0dp"android:layout_weight="1"><!-- contents of the third row --><!-- etc --></LinearLayout><Buttonandroid:id="@+id/solveButton"android:layout_width="fill_parent"android:layout_width="wrap_content" /><Buttonandroid:id="@+id/clearButton"android:layout_width="fill_parent"android:layout_width="wrap_content" /></LinearLayout>
Post a Comment for "How To Use Weights To Arrange Gridview Items Programmatically With Tablelayout"