即使重力是正确的,我的表动态布局仍然出现在左侧

时间:2014-05-26 09:06:13

标签: android xml android-layout layout android-tablelayout

我想要做的是制作动态表格布局..我的意思是行将使用文本视图动态填充并且滚动水平和垂直但每次当活动打开我的表格布局时从左侧开始显示即使我把引力设置为正确..为什么会发生这种情况?

这是我的xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right" >
 <HorizontalScrollView
     android:id="@+id/horizontalScrollView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
      <ScrollView
     android:id="@+id/scrollView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
 <TableLayout 
     android:id="@+id/table1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:stretchColumns="0,1"
     android:layout_gravity="right" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 

            android:gravity="right"
            android:layout_gravity="right">


        </TableRow>


    </TableLayout>
 </ScrollView>
 </HorizontalScrollView>
</LinearLayout>

这是我的java代码:

TableLayout ll = (TableLayout) findViewById(R.id.table1);
int razan=0;
int c=-1;
    for(int s=1; s<=fixed;s++){
        if(razan<=count){
            for (int i = 0; i <text.length; i++) {

                if(i>0 && i%7==0){
                    c = c+1;
                    TableRow row1= new TableRow(this);
                    TableRow.LayoutParams tr1 = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
                    row1.setLayoutParams(tr1);

                    TextView emptyrow = new TextView(this);
                    emptyrow.setText("");
                   // emptyrow.setBackground(getResources().getDrawable(R.drawable.back));

                    row1.addView(emptyrow);


                    ll.addView(row1,i);
                }
                TableRow row= new TableRow(this);
                TableRow.LayoutParams tr = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
                row.setLayoutParams(tr);

                TextView product = new TextView(this);
                TextView product_j = new TextView(this);


                product_j.setText(prodlist.get(razan));
                Resources res = getResources();

                Drawable drawable = res.getDrawable(R.drawable.back);
                product_j.setBackgroundDrawable(drawable);

                product_j.setGravity(Gravity.RIGHT);
                product_j.setTextSize(18);

                product.setText(text[i]);
             //   product.setBackgroundDrawable(drawable);
                product.setGravity(Gravity.RIGHT);
                product.setPadding(3, 0, 3, 0);
                product.setTextSize(18);
                row.addView(product_j);
                row.addView(product);

                razan++;
                ll.addView(row,i);
                //here is the code for adding an empty row after each seven inner rows !!!


            }//inner for

        }

}//outer fors

}

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

将您的根LinearLayouts高度和宽度设为match_parent,并在TableLayout上向右尝试重力