我下面的代码:如何中心对齐的ImageView在TableLayout细胞programmaticly
TableRow row = new TableRow(this);
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
lp.setMargins(0,5,0,0);
row.setLayoutParams(lp);
List<List<String>> cList2 = displayTemp.getCList2();
StringBuffer sb = new StringBuffer();
List<String> lStr = cList2.get(0);
for (int ix = 0; ix < lStr.size(); ix++) {
sb.append(lStr.get(ix));
if (ix != lStr.size() - 1) {
sb.append("\n");
}
}
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));
tv.setText(sb.toString());
tv.setTextSize(COMPLEX_UNIT_DIP, 20);
row.addView(tv);
byte[] decodedString = Base64.decode(cList2.get(1).get(0), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,decodedString.length);
ImageView iView = new ImageView(this);
iView.setImageBitmap(decodedByte);
row.addView(iView);
tableLayout2.addView(row, rowNum);
rowNum++;
此动态显示表行。我的第二个表格单元格中显示此代码,
byte[] decodedString = Base64.decode(cList2.get(1).get(0), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,decodedString.length);
ImageView iView = new ImageView(this);
iView.setImageBitmap(decodedByte);
row.addView(iView);
在第二小区中显示的图像,目前右对齐。我想将它显示为单元格中心对齐。我怎样才能做到这一点?
这并不为我工作。如何在表格的每个单元格周围显示边框(像像素一样的厚度),以便于对单元格的子对象进行可视化(如TextView或ImageView)。 – mukul
更新了答案 – Pehlaj