我有一个切换按钮,其大小如下:
protected int[] calculateCardWidth(int[] rowsCols) {
//Getting the screen size.
Display display = this.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
//cardWidHigh 0->width , 1 ->height.
cardWidHigh[0] = (int) (width / (rowsCols[1] + .25));
cardWidHigh[1] = (int) (height / (rowsCols[0] + 2));
return cardWidHigh;
}
我希望能够根据按钮大小(宽度和高度)的变化动态地更改文本大小,什么是实现此目的的最佳方法?
答案 0 :(得分:0)
您更改其LayoutParams的值,父级将使用新值在新位置重新渲染屏幕:
LayoutParams p = cardView.getLayoutParams();
p.width = cardWidth[0];
p.height = cardWidth[1];
cardView.setLayoutParams(p);
cardView.getViewParent().invalidate();