慕斯王
您可以使用以下代码更改每个视图的高度或宽度 :private void changeIncludes (View newView ){ LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) newView.getLayoutParams(); // change width and height to 50 params.height = 50 ; params.width = 50; newView.setLayoutParams(params); }或从其他视图大小使用:private void changeIncludes (View current , View newView ){ LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) newView.getLayoutParams(); params.height = current.getLayoutParams().height; params.width = current.getLayoutParams().width; newView.setLayoutParams(params); }如果宽度或高度没有改变,你应该刷新页面。这些代码对我有用,我希望对你也有用。checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked){ changeIncludes(buttonView,50,100); }else{ changeIncludes(buttonView,30,100); } } });private void changeIncludes (View newView , int h , int w){ LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) newView.getLayoutParams(); // change width and height to 50 params.height = h ; params.width = w; newView.setLayoutParams(params); }我将此代码用于复选框,但如果您想用于列表项,则只需更改侦听器和界面。