我是Android開發人員的初學者,我與以下人員鬥爭。 我想創建一個帶有編程創建的tablelayout的Fragment。 我在一個活動,而不是一個片段我做了第一次開始:使用滾動視圖和表格佈局的片段佈局限制
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = getLayoutInflater().inflate(R.layout.activity_testtable, null,false);
fillLayout(view);
setContentView(view);
}
protected void fillLayout(View rootView) {
TableLayout tl;
TableRow tr;
TextView tv;
int i = 0;
tl = (TableLayout) rootView.findViewById(R.id.time_range);
for (i = 0 ; i < 10 ; i++) {
tv = new CellWorkshopTable(this);
tv.setText("11h00 - 14h40");
tr = new TableRow (this);
tr.addView(tv);
tl.addView(tr);
}
[...]
}
它運作良好,創建表,因爲我在2軸等等等等,那我想這個設置成一個片段滾動想要的,所以我做了我的片段如下:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View aView = inflater.inflate(R.layout.activity_testtable, container, false);
fillLayout(aView);
return aView;
}
所以沒事的時候我犯的片段,在logcat中沒有錯誤出現,沒有崩潰,似乎一切都在那裏,但不顯示任何內容。
這裏是佈局,目的是有完整的結構,只是添加的TableRow和細胞(這是textviews):
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/time_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:padding="0dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="0dp" >
<TableLayout
android:id="@+id/time_range"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</TableLayout>
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp" >
<TableLayout
android:id="@+id/header_rooms"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</TableLayout>
<TableLayout
android:id="@+id/time_table_content"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
所以在寫這個問題我試圖簡化佈局通過移除HorizontalScrollView和他的孩子的,然後TableRows第一tablelayout添加,然後顯示
去除HorizontalScrollView但保持tableLayout + ID/header_rooms和tableLayout + ID/time_table_content,使header_rooms工作和time_table_content KO。
那麼碎片有佈局數量的限制,我怎麼能circonvent這個?