【发布时间】:2016-12-09 22:13:10
【问题描述】:
我在一个 Tablerow 中有 4 个 Imageview。它们通过layout_weight 命令进行缩放。我现在需要写在这个 Imageviews 中。有没有可能做到这一点而不必使用alignparent 意思是使用相对布局?
这是我目前的代码:
TableRow.LayoutParams params = new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
TableRow.LayoutParams params1 = new TableRow.LayoutParams(0,ViewGroup.LayoutParams.WRAP_CONTENT,1.2f);
TableRow.LayoutParams params2 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 2.4f);
TableRow.LayoutParams params3 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 3.6f);
TableRow.LayoutParams params4 = new TableRow.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 4.8f);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(params);
ImageView rank = new ImageView(this);
rank.setAdjustViewBounds(true);
rank.setLayoutParams(params1);
rank.setImageResource(R.drawable.whitebutton);
Layout[i] = new ImageView(this);
Layout[i].setLayoutParams(params2);
Layout[i].setImageResource(R.drawable.width2);
Layout[i].setAdjustViewBounds(true);
Layout[i+10] = new ImageView(this);
Layout[i+10].setLayoutParams(params3);
Layout[i+10].setImageResource(R.drawable.width3);
Layout[i+10].setAdjustViewBounds(true);
Layout[i+20] = new ImageView(this);
Layout[i+20].setLayoutParams(params4);
Layout[i+20].setImageResource(R.drawable.width4);
Layout[i+20].setAdjustViewBounds(true);
tableRow.addView(rank);
tableRow.addView(Layout[i]);
tableRow.addView(Layout[i+10]);
tableRow.addView(Layout[i+20]);
t.addView(tableRow);
好吧,另外还有4张相同大小的图片,里面有实际的高分
【问题讨论】:
标签: android android-layout android-relativelayout android-layout-weight