3 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
您不需要動態(tài)更改高度。只需將子列表放在類似于 LinearLayout 的 ViewGroup 中,View.VISIBLE
并View.GONE
在復(fù)選框更改之間切換可見性。

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
您可以使用以下代碼更改每個(gè)視圖的高度或?qū)挾?:
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);
}
如果寬度或高度沒有改變,你應(yīng)該刷新頁面。
這些代碼對我有用,我希望對你也有用。
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);
}
我將此代碼用于復(fù)選框,但如果您想用于列表項(xiàng),則只需更改偵聽器和界面。
添加回答
舉報(bào)