在RelativeLayout

时间:2016-05-23 03:02:00

标签: android tablelayout

我有一个名为“Grid”的表,在自己的类中创建......就像这样:

ScrollView contentView = new ScrollView(this);
        contentView.setBackgroundColor(Color.LTGRAY);

        // THIS IS OUR MAIN LAYOUT
         mainLayout = new RelativeLayout(this);

        // ADD MAINLAYOUT TO SCROLLVIEW (contentView)

       contentView.addView(mainLayout);

        // SET CONTENT VIEW

        setContentView(contentView);

        meTable = this.tableLayout();

        HorizontalScrollView HOR = new HorizontalScrollView(this);

        mainLayout.addView(HOR);

        HOR.addView(meTable);

这会创建表格,并且还会添加水平和垂直滚动条,这很棒......

但是,我需要将所有这些放在另一个RelativeLayout中,如下所示:

enter image description here

我可以这样做,但没有滚动条,我只需添加“meTable”,就像这样:

Grid gr = new Grid();
        gr.Activate(this);
        TableLayout tablita;

        RelativeLayout layout = (RelativeLayout) findViewById(R.id.contenedorLay);

        tablita = gr.meTable;


        layout.addView(tablita);

如何使用滚动条添加整个表?

1 个答案:

答案 0 :(得分:0)

看看这段代码,它对我有用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
 <ScrollView 
    android:id="@+id/layout" 
    android:layout_height="match_parent"         
    android:scrollbars="horizontal|vertical" 
    android:layout_width="match_parent"     
    android:layout_marginTop="5dip"     
    android:scrollbarStyle="outsideInset"
    android:fillViewport="true"> 

    <HorizontalScrollView 
        android:id="@+id/horizontalView" 
        android:layout_height="wrap_content"     
        android:scrollbars="horizontal|vertical" 
        android:layout_width="wrap_content"     
        android:layout_marginTop="5dip">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/tlGridTable" >   
        </TableLayout>
    </HorizontalScrollView>
</ScrollView>
</LinearLayout>
相关问题