0
那是我的選項卡。 如何在Android中將選項卡對齊中心?
我想將它對齊到屏幕中心。 (水平和垂直)
該表是從java動態創建的。
我試過設置
TableLayout t1 = (TableLayout)findViewById(R.id.maintable);
t1.setGravity(Gravity.CENTER);
但它只是從頂部對齊。
public class TabActivity extends Activity {
Trny t = Trny.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab);
TableLayout t1 = (TableLayout)findViewById(R.id.maintable);
t1.setGravity(Gravity.CENTER);
// first row of table
TableRow tr = new TableRow(this);
TextView place = new TextView(this);
poradi.setText("P" );
poradi.setPadding(10, 5, 10, 5);
tr.addView(place);
TextView nameOfTeam = new TextView(this);
nazTymu.setText("Nazev" );
nazTymu.setPadding(10, 5, 10, 5);
tr.addView(nameOfTeam);
TextView matchesPlayed = new TextView(this);
odehraneZapasy.setText("Z");
odehraneZapasy.setPadding(10, 5, 10, 5);
tr.addView(matchesPlayed);
TextView numbefOfWins = new TextView(this);
pocetVyher.setText("V");
pocetVyher.setPadding(10, 5, 10, 5);
tr.addView(numbefOfWins);
TextView numberOfTies = new TextView(this);
pocetRemiz.setText("R");
pocetRemiz.setPadding(10, 5, 10, 5);
tr.addView(numberOfTies);
TextView numberOfLoses = new TextView(this);
pocetProher.setText("P");
pocetProher.setPadding(10, 5, 10, 5);
tr.addView(numberOfLoses);
TextView goalsScored = new TextView(this);
skorePlus.setText("VG");
skorePlus.setPadding(10, 5, 10, 5);
tr.addView(goalsScored);
TextView goalsGained = new TextView(this);
skoreMinus.setText("OG");
skoreMinus.setPadding(10, 5, 10, 5);
tr.addView(goalsGained);
TextView numberOfPoints = new TextView(this);
pocBodu.setText("B");
pocBodu.setPadding(10, 5, 10, 5);
tr.addView(numberOfPoints);
t1.addView(tr);
//more rows dynamically created from java
}
}
XML文件
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/maintable" >
</TableLayout>
我怎樣才能做到這一點?多謝你們。
這應該有固定的。嘗試設置CENTER_HORIZONTAL和CENTER_VERTICAL。你應該在佈局文件中給它,因爲你不需要動態轉換。 – pvn