2013-11-28 5 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

Попробуйте сделать высоту вашего Scrollview к '' fill_parent' андроида: layout_height = "fill_parent" ' – GrIsHu

+0

нет удара, тот же результат – abdfahim

+0

@abdfahim вы исправить проблему? – Karthi

ответ

9

добавить эту строку в Scrollview XML ->

 android:fillViewport="true" 

Это позволяет раскладку дочернему взять полный экран, если это layout_width & layout_height is match_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> 
Смежные вопросы