Я несколько раз видел ScrollView без прокрутки на stackoverflow.com, но ни одно из предложенных решений не работает для меня. Я надеюсь, что кто-то может помочь.
У меня есть ScrollView, содержащий TableLayout. TableLayout пуст, но я программно вставляю строки и столбцы. Я предполагаю, что мне нужно сообщить ScrollView, что TableLayout был изменен/обновлен, и 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
//};
}