2013-04-24 168 views
2

我有一個動態地創建表格的活動。該活動已創建並正常工作。表格佈局不適合屏幕

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

我想表格填寫全框中,桌子右側的空間不是必需的,看起來很尷尬。要做到這一點需要做什麼?

回答

1

被要求的佈局這樣被編輯:

<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

1

你的表格佈局寬度包裹它的內容,它應該是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

1

做的修改爲:

<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

1

的目的是什麼使用Horizo​​ntalScrollView?只需刪除它,並將TableLayout的android:layout_width設置爲match_parent。

2

更好的伸展和收縮的所有列有適合您的屏幕:

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

</TableLayout>