2013-03-04 96 views
0

我是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> 

所以在写这个问题我试图简化布局通过移除Horizo​​ntalScrollView和他的孩子的,然后TableRows第一tablelayout添加,然后显示

去除Horizo​​ntalScrollView但保持tableLayout + ID/header_rooms和tableLayout + ID/time_table_content,使header_rooms工作和time_table_content KO。

那么碎片有布局数量的限制,我怎么能circonvent这个?

回答

0

事实上,通过清理布局中的所有不必要的元素,它的工作原理如图所示。

因此,片段似乎对布局元素组合更“严格”。