我正在使用带有动态视图的ViewPager,如此链接所示.我将每个页面添加到viewpager.创建每个页面并将其添加到寻呼机适配器的代码如下
public View createPage( )
{
TableLayout table = new TableLayout(mycontext);
TableRow row = new TableRow(mycontext);
for(int i=0; i <= num_of_views; i++)
{
TableLayout catTable = new TableLayout(mycontext);
TableLayout.LayoutParams params = new TableLayout.LayoutParams();
params.height = LayoutParams.MATCH_PARENT;
TableRow catName = new TableRow(mycontext);
catName.setGravity(0x03);
catName.setLayoutParams(params);
TextView cat = new TextView(mycontext);
TableRow.LayoutParams RowParams=
new TableRow.LayoutParams(pixeltoDp(0),pixeltoDp(85));
RowParams.weight = 1;
cat.setLayoutParams(RowParams);
cat.setPadding(35, 0, 5, 0);
cat.setGravity(0x13);
cat.setSingleLine(true);
cat.setHorizontallyScrolling(true);
cat.setFocusable(true);
cat.setFocusableInTouchMode(true);
cat.setLines(1);
cat.setText(data.getCats().get(i).getName());
cat.setTextColor(color);
cat.setSelected(true);
catName.addView(cat);
catTable.addView(catName);
for(int j=0; j < 5; j++)
{ …Run Code Online (Sandbox Code Playgroud)