2013-11-28 79 views
2

我希望ScrollView TableLayout与屏幕具有相同的高度,但为什么表只占用屏幕的一半,而ScrollView则按照预期全屏显示。Android TableLayout ScrollView

我试着改变表和行的高度作为wrap_content,但显示相同的结果。同样改变桌子的高度作为固定高度(例如900dp)也不适用。即使最后一排高度也没有显示完整的评级栏。好像表格被强制具有特定的宽度。

如果我删除ScrollView,它工作得很好。

任何人都可以请帮忙。

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="@drawable/border" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".EditEntry" > 
    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TableRow 
      android:id="@+id/tr3a" 
      android:padding="2.5dp" 
      android:background="@color/col1" 
      android:gravity="center_vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
     android:layout_weight="1" > 

      <TextView 
       android:id="@+id/lab_bookname" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/bookname" /> 

      <EditText 
       android:id="@+id/bookname" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/definputtext2" /> 

     </TableRow> 

     <TableRow 
      android:id="@+id/tr3" 
      android:padding="2.5dp" 
      android:background="@color/col2" 
      android:gravity="center_vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
     android:layout_weight="1" > 
      <TextView 
       android:id="@+id/lab_printname" 
      android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/print_name" /> 

      <EditText 
       android:id="@+id/printname" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="@string/definputtext2" /> 

     </TableRow> 
     ...................... 
     ...................... 
     ...................... 
    </TableLayout> 
</ScrollView> 

enter image description here

+0

尽量让你的滚动视图为''fill_parent'机器人的高度:layout_height = “FILL_PARENT”' – GrIsHu

+0

没有影响,同样的结果 – abdfahim

+0

@abdfahim你解决问题了吗? – Karthi

回答

9

在滚动视图XML加入这行 - >

 android:fillViewport="true" 

这使得子布局,以充分屏幕,如果是layout_width & layout_heightmatch_parent/fill_parent。。在你的情况下,TableLayout将得到使用这条线的全尺寸..!请享用...!

+0

我也面临同样的问题,但你的解决方案不解决我的问题可以请帮助我http://stackoverflow.com/questions/38588702/why-my-scrollview-not-working-properly – Karthi

+0

完美!谢谢 –

0

把一个线性布局放在作品之间,但我不知道为什么直接设置一些高度到表视图不起作用。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/black" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context=".EditEntry" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@android:color/darker_gray" > 

      <TableLayout 
       android:id="@+id/tableLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="1000dp" > 

       <TableRow 
        android:id="@+id/tr3a" 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@color/col1" 
        android:gravity="center_vertical" 
        android:padding="2.5dp" > 

        <TextView 
         android:id="@+id/lab_bookname" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/bookname" /> 

        <EditText 
         android:id="@+id/bookname" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:hint="@string/definputtext2" /> 
       </TableRow> 

       <TableRow 
        android:id="@+id/tr3" 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:background="@color/col2" 
        android:gravity="center_vertical" 
        android:padding="2.5dp" > 

        <TextView 
         android:id="@+id/lab_printname" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="@string/print_name" /> 

        <EditText 
         android:id="@+id/printname" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:hint="@string/definputtext2" /> 
       </TableRow> 
      </TableLayout> 
     </LinearLayout> 

    </ScrollView>