在我的应用程序中,我使用ViewPager,RelativeLayout和GridView创建可滚动视图,但GridView也是可滚动的。但我需要使用包含ImageView和TextView的两行来创建视图。我可以在这个问题上使用TableLayout,还是有其他GridView用法的解决方案?
答案 0 :(得分:1)
Ya你可以在下面的代码中使用table layout.try。
TableRow tableRow = null;
TextView textView = null;
ImageView imageView = null;
TableLayout tableLayout = (TableLayout)findViewById(R.id.tableLayout);
RelativeLayout relativeLayout = null;
for (String string: listOfStrings)
{
tableRow = new TableRow(this);
relativeLayout = (RelativeLayout) View.inflate(this, R.layout.row, null);
textView = (TextView) relativeLayout.getChildAt(0);
textView.setText(string);
imageView= (ImageView) relativeLayout.getChildAt(1);
imageView.setBackgroundColor(R.color.blue);
TableLayout.LayoutParams rlParams = new TableLayout.LayoutParams(FILL_PARENT, WRAP_CONTE);
tableRow.addView(relativeLayout, rlParams);
tableLayout.addView(tableRow);
}