Android: How to make the views the same height dynamically

爱⌒轻易说出口 提交于 2020-02-25 23:28:12

问题


I'm making one table in Android application. Now I cannot make the views the same height.

  • There are 2 TextViews, tmp_name and tmp_content in each row.
  • the height of tmp_content depends on the length of course_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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!