Я хочу, чтобы мой стол занимал весь экран с интервалом между столбцами и строками. Я динамически создаю строки в java в зависимости от количества игроков. Где в java-коде я добавляю свойства так, чтобы таблица занимала весь экран. Но я не мог этого добиться. Ниже приведен мой код и xml-файл.Таблица, чтобы снять весь экран в android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="views.controllers.RoundInfo">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addRound"
android:text="@string/addround" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@string/roundinfo"
android:textSize="30sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/maintable"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
public void addData() {
numOfPlayers = currentRound.getPlayers().size();
row = new String[numOfPlayers];
for (int i = 0; i < numOfPlayers; i++) {
row[i] = currentRound.getPlayers().get(i).getPlayer().getName();
}
col = new String[]{"Winner", "Seen", "Less", "Points"}; // get from database
int rowCount = row.length;
for (int i = 0; i <= rowCount; i++) {
TableRow tableRow = new TableRow(this);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT);
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tableRow.setLayoutParams(tableRowParams);
// create tableRow
for (int j = 0; j <= 4; j++) {
//create textView
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
CheckBox checkBox = new CheckBox(this);
EditText point = new EditText(this);
if (i == 0 && j == 0) {
textView.setText(" ");
tableRow.addView(textView);
} else if (i > 0 && j == 0) {
textView.setText(row[i - 1]); // Player Header
tableRow.addView(textView);
} else if (i == 0 && j != 0) {
textView.setText(col[j - 1]); //Game Header
tableRow.addView(textView);
} else if (i > 0 && j == 1) {
checkBox.setText(""); // Is Winner
tableRow.addView(checkBox);
} else if (i > 0 && j == 2) {
checkBox.setText(""); // Is Seen
tableRow.addView(checkBox);
} else if (i > 0 && j == 3) {
checkBox.setText(""); // Is Less
tableRow.addView(checkBox);
} else if (i > 0 && j == 4) {
point.setInputType(100); // Points
tableRow.addView(point);
}
}
tl.addView(tableRow);
}
}
Вы должны использовать TableLayout. Это упростит ситуацию. Просто предложение после прочтения того, что вы пытаетесь сделать. – AndroidMechanic