stackoverflow.com でスクロールできない ScrollView を数回見たことがありますが、提案された解決策はどれもうまくいきません。誰かが助けてくれることを願っています。
TableLayout を含む ScrollView があります。TableLayout は空ですが、プログラムで行と列を挿入します。TableLayout が変更/更新されたことを ScrollView に伝える必要があると推測しています。スクロールを有効にする必要がある場合は、ScrollView を再計算する必要があります。
ScrollView と TableLayout の両方を無効にしようとしました。 requestLayout() を試しましたが、何もしないようです。私は何が欠けていますか?
ここに私のレイアウトXMLがあります:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="horizontal|vertical" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:id="@+id/maintable" >
</TableLayout>
</ScrollView>
そして、これが私のJavaコードです。基本的に、このコードはプレーヤーごとに行を追加し、各プレーヤーの横に 25 個のボタンを追加します。ボタンはありますが、画面の境界からはみ出しています。
// Get the TableLayout
TableLayout tl = (TableLayout) findViewById(R.id.maintable);
// Go through each item in the array
for (int player = 0; player < players.length; player++)
{
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setId(100+player);
tr.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to add the player name
TextView labelTV = new TextView(this);
labelTV.setId(200+player);
labelTV.setText(players[player]);
//labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// numShots = 25
for (int shot = 0; shot < numShots; shot++)
{
Button shotButton = new Button(this);
shotButton.setId((player * 100) + shot);
shotButton.setText(Integer.toString(shot));
tr.addView(shotButton);
}
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// Add the TableRow to the TableLayout
//};
}