1
我得到了一個自定義對話框,其中包含一個複選框。當我檢查複選框時,會創建新視圖並將其添加到對話框中。如果我取消選中複選框,它將使視圖添加並將其更改回以前的視圖。如何使對話逐漸變大而不是立即
這是它的樣子。左側的圖片在檢查之前,左側在檢查之後。
隨着對話框被選中,對話框的佈局將變得更大,如上圖所示。
我的問題是如何使對話框佈局逐漸變得更大而不是瞬間變大。 類似於使佈局逐漸展開的動畫。
這是我迄今的工作。
public class CreateRoomDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//Get layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
//R.layout.add_player2 is the layout shows on dialog message
view = inflater.inflate(R.layout.createroom_dialog_fragment, null);
roomName = (EditText)view.findViewById(R.id.createroom_dialog_roomname);
roomKey = (EditText)view.findViewById(R.id.createroom_dialog_key);
keyLayout = (LinearLayout)view.findViewById(R.id.keyLayout);
checkBoxLayout1 = (RelativeLayout)view.findViewById(R.id.createroom_dialog_layout1);
checkBoxLayout2 = (RelativeLayout)view.findViewById(R.id.createroom_dialog_layout2);
// lock the room with key
checkBox1 = (CheckBox)view.findViewById(R.id.createroom_dialog_checkbox1);
// show the key
checkBox2 = (CheckBox)view.findViewById(R.id.createroom_dialog_checkbox2);
checkBox1.setOnCheckedChangeListener(new CreateRoomCheckBoxListener());
checkBox2.setOnCheckedChangeListener(new CreateRoomCheckBoxListener());
}
private class CreateRoomCheckBoxListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(buttonView == checkBox1){
// lock the room with key
if(isChecked){
roomKey.setVisibility(View.VISIBLE);
checkBoxLayout2.setVisibility(View.VISIBLE);
}else{
roomKey.setVisibility(View.GONE);
checkBoxLayout2.setVisibility(View.GONE);
}
}
}
}
}
謝謝你的鏈接。而你的假設是正確的,我知道日本人:) – edisonthk 2013-04-25 09:30:56