这里是我的xml:TableLayout没有定心
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
>
<TextView
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<TextView
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</TableRow>
我动态生成的休息。
现在它在屏幕上水平居中,但一切都在左侧。我知道它是一个简单的修复,但我似乎无法做到。
这里是我的手工代码:
for(Item l : leaders)
{
// Make a new row
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView name= new TextView(this);
TextView score = new TextView(this);
createView(row, name, l.getName());
createView(row, score, String.valueOf(l.getScore()));
name.setTextColor(Color.MAGENTA); // Just to distinguish between the columns
// Add row to table layout
tl.addView(row);
}
}
private void createView(TableRow row, TextView textView, String string)
{
textView.setText(string);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
textView.setTextColor(Color.CYAN);
textView.setTextSize(32);
textView.setPadding(20, 0, 0, 0);
row.setPadding(0, 1, 0, 1);
row.addView(textView);
}
而且,在给定的答案并没有改变布局。
1 snap = 1000 words。 –
当你说“它集中它,但一切都在左边”时,它很难描绘出来。 @paresh正在制定的是哪一点?截图会非常有帮助。 –
拍摄手机的屏幕。表格行按照水平居中对齐,但是左对齐。 – segFault