表格布局不适合屏幕

问题描述:

我有一个动态地创建表格的活动。该活动已创建并正常工作。表格布局不适合屏幕

这是xml文件的源代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#142c57" 
    tools:context=".TableActivity" > 

    <TextView 
     android:id="@+id/heading_textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:text="@string/followup_list" 
     android:textColor="#FFFFFF" 
     android:textSize="15sp"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/heading_textView" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:padding="3dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/inner_box"> 

      <ScrollView 
       android:id="@+id/scrollView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" > 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" > 

        <HorizontalScrollView 
         android:id="@+id/horizontalScrollView1" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_alignParentTop="true" > 

         <TableLayout 
          android:id="@+id/follow_up_table" 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:stretchColumns="0"> 


         </TableLayout> 

        </HorizontalScrollView> 

       </RelativeLayout> 

      </ScrollView> 

     </RelativeLayout> 

    </RelativeLayout> 

</RelativeLayout> 

的XML文件的输出:

output

我想表格填写全框中,桌子右侧的空间不是必需的,看起来很尴尬。要做到这一点需要做什么?

被要求的布局这样被编辑:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#142c57" 
    tools:context=".TableActivity" > 

    <TextView 
     android:id="@+id/heading_textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:text="@string/followup_list" 
     android:textColor="#FFFFFF" 
     android:textSize="15sp"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/heading_textView" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="10dp" 
     android:padding="3dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:background="@drawable/inner_box"> 

      <ScrollView 
       android:id="@+id/scrollView1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentTop="true" > 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" > 

        <TableLayout 
         android:id="@+id/follow_up_table" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentLeft="true" 
         android:layout_alignParentTop="true" 
         android:stretchColumns="0,1"> 


        </TableLayout> 

       </RelativeLayout> 

      </ScrollView> 

     </RelativeLayout> 

    </RelativeLayout> 

</RelativeLayout> 

输出

Output

+0

发现差异并不容易,让我发现它吧... android:stretchColumns =“0,1” – 2015-09-21 15:52:56

你的表格布局宽度包裹它的内容,它应该是match_parent

<TableLayout 
android:id="@+id/follow_up_table" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:stretchColumns="0"> 


</TableLayout> 
+0

试过这个,不能正常工作 – kittu88 2013-04-24 12:41:24

做的修改为:

<TableLayout 
    android:id="@+id/follow_up_table" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:stretchColumns="0"> 
</TableLayout> 

变化是:

android:layout_width="**fill_parent**" 
+0

没有工作的兄弟,结果是一样的 – kittu88 2013-04-24 12:52:58

的目的是什么使用Horizo​​ntalScrollView?只需删除它,并将TableLayout的android:layout_width设置为match_parent。

更好的伸展和收缩的所有列有适合您的屏幕:

<TableLayout 
android:id="@+id/follow_up_table" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:stretchColumns="*" 
android:shrinkColumns="*"> 

</TableLayout>