问题
I'm making one table in Android application. Now I cannot make the views the same height.
- There are 2
TextView
s,tmp_name
andtmp_content
in each row. - the height of
tmp_content
depends on the length ofcourse_description(i)
. tmp_content
sets its height automatically.
I'd like to get the height of tmp_content
and reset the height of tmp_name
same with tmp_content
.
If you have any tips, please let me know.
for (int i = 0; i < course_name.size(); i++) {
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
lp.setMargins(1, 1, 1, 1);
TextView tmp_name = new TextView(General.this);
tmp_name.setText(course_name.get(i));
tmp_name.setPadding(10, 0, 10, 0);
tmp_name.setLayoutParams(lp);
tmp_name.setBackgroundColor(getResources().getColor(R.color.white));
TextView tmp_content = new TextView(General.this);
tmp_content.setHorizontallyScrolling(false);
tmp_content.setPadding(10, 0, 10, 0);
tmp_content.setLayoutParams(lp);
tmp_content.setBackgroundColor(getResources().getColor(R.color.white));
tmp_content.setText(course_discription.get(i));
TableRow tmp_row = new TableRow(General.this);
tmp_row.addView(tmp_name);
tmp_row.addView(tmp_content);
tmp_row.setGravity(Gravity.CENTER_VERTICAL);
course_display.removeView(tmp_row);
course_display.addView(tmp_row);
}
来源:https://stackoverflow.com/questions/11722646/android-how-to-make-the-views-the-same-height-dynamically