如上所述,我如何在一个单元格中放置2个视图tablerow?我创建了一个表格布局,按代码添加行.
以下是我的代码:
TableLayout v = (TableLayout)inflater.inflate(R.layout.featureitem2, null);
// v.setColumnStretchable(0, true);
//adds each productname to the table
if(productName.size()>1){
TableRow pnamesRow = new TableRow(t);
pnamesRow.addView(new View(t));
for(int j=0;j < productName.size();j++){
LinearLayout wrap = new LinearLayout(t);
LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT);
wrap.setLayoutParams(params);
wrap.setOrientation(LinearLayout.HORIZONTAL);
wrap.setVisibility(View.VISIBLE);
ImageView remove = new ImageView(t);
remove.setTag(j);
remove.setClickable(true);
remove.setImageDrawable(t.getResources().getDrawable(R.drawable.remove));
remove.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
int deletePosition = (Integer)arg0.getTag();
Log.v("pos","pos="+deletePosition);
removeChild(deletePosition);
notifyDataSetChanged();
}
});
TextView pname = new TextView(t);
pname.setText(productName.get(j));
pname.setGravity(Gravity.CENTER);
// wrap.addView(pname);
wrap.addView(remove);
wrap.setLayoutParams(params);
pnamesRow.addView(pname); …Run Code Online (Sandbox Code Playgroud)