2015-07-20 59 views
0

下面是一个mainActivity代码滚动视图中使用Android的布局吹气

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_show); 

     tableLayout = (TableLayout) findViewById(R.id.tableLayout); 
     tableLayout.setVerticalScrollBarEnabled(true); 
     for (Integer j = 0; j < count; j++) { 
      //Rows will add till condition is true 
     } 
    } 

XML文件:layout_show

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/tableLayout" 
     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" >It has eight headers for eight columns in it 

</TableLayout> 

XML要滚动table_item.xml

<?xml version="1.0" encoding="utf-8"?> 

    <TableRow 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/table1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="2dp" 
     android:layout_alignParentRight="true" 
     android:background="@color/LightPink">---Columns defined here---- 
    </TableRow> 

一切工作正常

  1. 不同列的单行数据取自不同的来源。

  2. table_item.xm中使用ScrollView l不起作用,但干扰了标题和项目列的对齐。

结果要实现的是:

  1. 保持头,但滚动table_item.xml

希望我得到一些线索的充气行...

谢谢时间

+0

我不明白这里有什么确切的问题。你能说清楚你的问题吗? – Vesko

+0

感谢Vesko的回复..当for循环的次数超过12时,在12之后添加的其他行不能被看到,除非屏幕较大,所以需要向上滚动(垂直)。但我无法达到预期的效果。 –

回答

0

TableLayout不是滚动条标签容器本身,因此你描述的行为是正常的。最简单的解决方案是将TableLayout换成ScrollView。您可以在layout_show.xml文件中执行此操作。

+0

由于Vesko试图通过编程和XML在单独和一起,但没有工作。在尝试了其他可能的方法后,决定继续编写adapter.java类来转换视图。但是如果工作的话会这样。显然,因为这是更简单的方法 –