【问题标题】:Insert TableLayout with scrollbars inside a RelativeLayout在 RelativeLayout 中插入带有滚动条的 TableLayout
【发布时间】:2016-05-24 04:05:45
【问题描述】:

我有一个名为“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 中,如下所示:

我可以这样做,但没有滚动条,我只需添加“meTable”,如下所示:

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

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

        tablita = gr.meTable;


        layout.addView(tablita);

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

【问题讨论】:

    标签: android tablelayout


    【解决方案1】:

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

    <?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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-10
      • 2012-01-09
      • 1970-01-01
      • 2013-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多