Android 如何使用权重通过TableLayout以编程方式排列Gridview项
我正在开发Suduko解算器应用程序。我希望布局在9个GridView中具有9x9 TextView。我想在它们下面放两个按钮(求解,清除)。我已经做了,但它可能不适用于小型设备(看不到按钮,网格视图变成了不适合屏幕的滚动视图) 下面是我如何将TextView添加到Gridview的Android 如何使用权重通过TableLayout以编程方式排列Gridview项,android,android-layout,gridview,android-tablelayout,Android,Android Layout,Gridview,Android Tablelayout,我正在开发Suduko解算器应用程序。我希望布局在9个GridView中具有9x9 TextView。我想在它们下面放两个按钮(求解,清除)。我已经做了,但它可能不适用于小型设备(看不到按钮,网格视图变成了不适合屏幕的滚动视图) 下面是我如何将TextView添加到Gridview的 gridView = (GridView) findViewById(R.id.gridView1); String[] arrayEmpty = new String[] {"", "", "", "", "",
gridView = (GridView) findViewById(R.id.gridView1);
String[] arrayEmpty = new String[] {"", "", "", "", "", "", "", "", ""};
ArrayList<String> listEmpty = new ArrayList<String>(Arrays.asList(arrayEmpty));
gridView.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,list));
gridView=(gridView)findViewById(R.id.gridView1);
String[]arrayEmpty=新字符串[]{“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”};
ArrayList listEmpty=新的ArrayList(Arrays.asList(arrayEmpty));
setAdapter(新的ArrayAdapter(this,R.layout.list_项,list));
这是我的Layout.XML
<?xml version="1.0" encoding="utf-8"?>
这是我的截图
但这正是我需要的布局与所有设备。也许我应该用举重,但我不知道怎么用
检查这个数独项目- 也
在这里你可以找到数独游戏的布局和源代码以及其他有用的东西。检查这个数独项目- 也
在这里您可以找到数独的布局和源代码以及其他有用的东西。这里有一个技巧:对于完全统一的表或网格,您根本不需要TableView或GridView。只需将所有内容放入LinearLayout中,大小为0,布局重量为1。size=0似乎违反直觉,但与layoutwweight=1相结合,它的效果是让所有子窗口小部件都具有完全相同的大小,而不管它们的内容如何 因此,请这样做:
这里有一个技巧:对于完全统一的表或网格,您根本不需要TableView或GridView。只需将所有内容放入LinearLayout中,大小为0,布局重量为1。size=0似乎违反直觉,但与layoutwweight=1相结合,它的效果是让所有子窗口小部件都具有完全相同的大小,而不管它们的内容如何 因此,请这样做:
注意:我把它作为一个练习留给学生,让他们知道如何在需要的地方添加页边距。好的,但是我应该如何将TextView添加到.java文件中的每个视图中(以编程方式)?LinearLayout不处理缓存,如果在其中放置太多视图,足以耗尽内存,应用程序将崩溃。但在gridview或listview中,这种情况不会发生。注意:我把它作为一个练习留给学生,让他们知道如何在需要的地方添加边距。好的,但是我应该如何(以编程方式)将TextView添加到.java文件的每个视图中?LinearLayout不处理缓存,如果在其中放置太多视图,足以耗尽内存,应用程序将崩溃。但在gridview或listview中,这不会发生。
<TableRow android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:background="#999999"
android:layout_weight="1"
android:layout_height="match_parent">
<GridView
android:id="@+id/gridView1"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView2"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView3"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<TableRow android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:background="#999999"
android:layout_weight="1"
android:layout_height="match_parent">
<GridView
android:id="@+id/gridView4"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView5"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView6"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<TableRow android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:background="#999999"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginBottom="15dp">
<GridView
android:id="@+id/gridView7"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView8"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<GridView
android:id="@+id/gridView9"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#5C5C5C"
android:layout_weight="1"
android:numColumns="3" >
</GridView>
<TableRow android:layout_weight="1" android:layout_height="match_parent">
<Button
android:id="@+id/solve_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="@string/solve" />
<Button
android:id="@+id/clear_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="@string/_clear" />
</TableRow>