2015-07-21 174 views
0

我正在使用垂直滚动视图的表格布局来显示数据programmaticlly的巨大列表。在平板电脑上,它的工作原理是一种完美的方式,但是当我在诸如银河或连线等手机上运行时会出现问题1表格布局的宽度与屏幕宽度不匹配,因此隐藏了两列或三列我尝试了所有组合match_parent,WRAP_CONTENT ......我用了一个水平滚动查看它的工作原理,但我不认为这是一个很好的解决方案 这是XML文件:android表格布局不适合屏幕

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="..." 
    > 
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/mv_table" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_marginTop="50dp"> 
    </TableLayout> 
</RelativeLayout> 
</ScrollView> 

这是我的代码:

TableLayout mvtable = (TableLayout) findViewById(R.id.mv_table); 
     TableRow tr_head = new TableRow(this); 
     tr_head.setId(10); 
     tr_head.setBackgroundColor(Color.rgb(24,65,95)); 
     TextView label_Date = new TextView(this); 
     label_Date.setId(20); 
     label_Date.setText("Date"); 
     label_Date.setTextColor(Color.WHITE); 
     label_Date.setPadding(5, 5, 5, 5); 
     tr_head.addView(label_Date); 

     TextView label_Debit = new TextView(this); 
     label_Debit.setId(21); 
     label_Debit.setText("Débit"); 
     label_Debit.setTextColor(Color.WHITE); 
     label_Debit.setPadding(5, 5, 5, 5); 
     tr_head.addView(label_Debit); 

..... 

    tr_head.setLayoutParams(new TableRow.LayoutParams(
       TableRow.LayoutParams.FILL_PARENT, 
       TableRow.LayoutParams.WRAP_CONTENT)); 
     mvtable.addView(tr_head, new TableLayout.LayoutParams(
       TableLayout.LayoutParams.FILL_PARENT, 
       TableLayout.LayoutParams.WRAP_CONTENT)); 

     //setting data programmaticlly 
     int c ; 
     int i=1; 

     for (Movement mv : movementsList) 
     { 

      TableRow tr = new TableRow(this); 
      if (i % 2 != 0) 
      { 
       c=Color.WHITE; 

       tr.setBackgroundColor(Color.GRAY);} 
      else 
      {c=Color.BLACK; 
      } 
      tr.setId(100 + i); 
      tr.setLayoutParams(new TableRow.LayoutParams(
        TableRow.LayoutParams.FILL_PARENT, 
        TableRow.LayoutParams.WRAP_CONTENT)); 



      TextView labelDate = new TextView(this); 
      labelDate.setId(200+i); 
      labelDate.setText(mv.getDate()); 
      labelDate.setTextColor(c); 
      labelDate.setPadding(5, 5, 5, 5); 
      tr.addView(labelDate); 


      TextView labelDebit = new TextView(this); 
      labelDebit.setId(210+i); 
      labelDebit.setText(mv.getDebit()); 
      labelDebit.setTextColor(c); 
      labelDebit.setPadding(5, 5, 5, 5); 
      labelDebit.setBackgroundColor(Color.rgb(255,174,185)); 
      tr.addView(labelDebit); 

...... 



      tr.setLayoutParams(new TableRow.LayoutParams(
        TableRow.LayoutParams.FILL_PARENT, 
        TableRow.LayoutParams.WRAP_CONTENT)); 

      mvtable.addView(tr, new TableLayout.LayoutParams(
        TableLayout.LayoutParams.FILL_PARENT, 
        TableLayout.LayoutParams.WRAP_CONTENT)); 
      i++; 
     } 

回答

0

使用LinearLayout而不是RelativeLayout它可能会解决您的问题。因为RelativeLayout重叠在其他

+0

做到了,但相同 – elpazio