私は数独を構築していますが、ここでパフォーマンスの問題に直面しています。
私はこのグリッドを持っており、グリッドを 81 個のセルで埋めたいと思っています。これらのセルはカスタム ビューです。関数 blabla に 10 個のラベルを付けたいからです。
私の問題は、81個のサブビューを作成し(問題ありません)、モデルのデータを入力して(問題ありません)、グリッド全体をレイアウトに追加する必要があることです(biiiig問題)。
構築全体は、次のような asynctask で行われます。
protected Void doInBackground(Void... params) {
Model.Cell[][] sudoku = Controller.getInstance().startNewGame(); //call model for a new game
ArrayList<TableRow> rows = ga.generateTable(sudoku); //generate the table
tl = new TableLayout(ga); //create tablelayout
//add the rows to the layout
for (TableRow v : rows) {
tl.addView(v);
}
return null;
}
次に、これが行われた後:
protected void onPostExecute(Void result) {
super.onPostExecute(result);
RelativeLayout rl = (RelativeLayout) ga.findViewById(R.id.gridContainer); //get the container
//create layout rules
android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
//add the table to the container with the layout
rl.addView(tl, params); //this is slow as hell.
//stop loading indicator
this.loading.dismiss();
}
しばらくの間、読み込みバーを取得してもかまいません。しかし、 rl.addView(tl, params) が非常に遅いため、読み込みバーが停止しています。
メインスレッドを高速に保つ方法を教えてください。