3 回答
TA贡献1831条经验 获得超4个赞
您不需要动态更改高度。只需将子列表放在类似于 LinearLayout 的 ViewGroup 中,View.VISIBLE
并View.GONE
在复选框更改之间切换可见性。
TA贡献1864条经验 获得超2个赞
您可以使用以下代码更改每个视图的高度或宽度 :
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);
}
我将此代码用于复选框,但如果您想用于列表项,则只需更改侦听器和界面。
添加回答
举报