2014-03-05 41 views
1

目前我正在尝试在android中的运行时创建一个基本的tablelayout。我已经尝试了Wrap_Content,Match_Parent和每个组合的重量,但似乎没有任何工作。如何强制TableLayout适合整个屏幕?

基本上我想这样的:

 Title 

文本* ** * ** *文字A1

化文本B * ** * ** *文本B1

文本C * ** * ** *文C1

*意味着空格(对不起,我无法弄清楚如何格式化它)。我希望这样继续下去,以便它在水平和垂直方向上都能充满屏幕。目前,我可以使其适合屏幕水平,但它留下一个大的空白空间在底部。

我的XML是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/blackboard" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:text="Classes" 
    android:textColor="@color/white" 
    android:textSize="25sp" 
    android:textStyle="bold" 
    android:typeface="serif" /> 
<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:scrollbars="none" 
    android:layout_weight="1"> 
    <TableLayout 
     android:id="@+id/displayTableForClasses" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:shrinkColumns="*" 
     android:stretchColumns="*" > 

</TableLayout> 
</ScrollView> 

我本质上需要的是字体缩放,使得其将垂直填满整个屏幕,不缠绕的方式。最好的情况是,这种情况下字体大小应尽可能大,而不要导致环绕,然后增加不同TextView之间的边距,使其填满整个屏幕。

回答

1

您需要首先更改父布局中的宽度和高度。 例如,如果您使用的RelativeLayout你需要改变布局的属性,如:

android:layout_width="fill_parent" 
android:layout_height="fill_parent" 

,然后在你TableLayout,你可以使用

android:layout_width="match_parent" 
android:layout_height="match_parent" 

使用这一个:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView1" /> 

      <TextView 
       android:id="@+id/textView4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="TextView4" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <TextView 
       android:id="@+id/textView2" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="TextView2" /> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="TextView3" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

+0

让我用我的新XML进行编辑。它仍然不起作用。我真正想要的是一种制作setMargins(15,15,15,15)的方式,它可以将整个屏幕垂直地放置(也可以使垂直边缘更大,以使它适合整个屏幕与项目for循环)。 –

+0

我已经把另一个代码。我以不同的方向使用LinearLayout来管理TextView –