返回Android对话框视图?
我正在使用此代码创建一个自定义对话框。这很好,但出于某种原因,我想返回或获取对话框视图。这就是原因:我想为对话框设置动画,以实现对话框内部的展开/折叠功能,为此,我需要对话框的视图返回Android对话框视图?,android,dialog,Android,Dialog,我正在使用此代码创建一个自定义对话框。这很好,但出于某种原因,我想返回或获取对话框视图。这就是原因:我想为对话框设置动画,以实现对话框内部的展开/折叠功能,为此,我需要对话框的视图 final Dialog dialog = new Dialog(getActivity(), R.style.CustomDialog); dialog.setContentView(R.layout.dialog_en
final Dialog dialog = new Dialog(getActivity(),
R.style.CustomDialog);
dialog.setContentView(R.layout.dialog_enter_name);
dialog.setTitle("Hello");
Button dialogButtonOK = (Button) dialog
.findViewById(R.id.dialogButtonOK);
Button dialogButtonCancel = (Button) dialog
.findViewById(R.id.dialogButtonCancel);
nameField = (EditText) dialog.findViewById(R.id.nameField);
lastNameField = (EditText) dialog
.findViewById(R.id.familyField);
//And some code for OK/Cancel button.
这是我将用来设置对话框动画的类。如您所见,它需要一个视图
public class HeightAnimation extends Animation {
protected final int originalHeight;
protected final View view;
protected float perValue;
public HeightAnimation(View view, int fromHeight, int toHeight) {
this.view = view;
this.originalHeight = fromHeight;
this.perValue = (toHeight - fromHeight);
}
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
view.getLayoutParams().height = (int) (originalHeight + perValue
* interpolatedTime);
view.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
}
这就是我如何使用上面的类:
HeightAnimation heightAnim = new HeightAnimation(dialogview, 100, 400);
heightAnim.setDuration(1000);
dialogview.startAnimation(heightAnim);
我上面使用的dialogview应该是该对话框的视图。但我不知道该怎么做
编辑:我刚刚发现如何做到这一点:
final Dialog dialog = new Dialog(getActivity(),
R.style.CustomDialog);
LayoutInflater factory = LayoutInflater.from(getActivity());
final View dialogview = factory.inflate(
R.layout.dialog_enter_name, null);
dialog.setContentView(dialogview);