1、首先获取布局的根视图View
View rootView = LayoutInflater.from(mContext).inflate(R.layout.layout_dialog_wlan_input_password, null);
2、获取dailog中需要移动位置的布局;
LinearLayout mLlWifiWlanInputPswContainer = rootView.findViewById(R.id.rl_wifi_wlan_input_psw_container);
3、在dialog的show方法中添加监听
// 监听软键盘弹起/隐藏
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//获取当前根视图在屏幕上显示的大小
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int visibleHeight = r.height();
// 初始化时,根视图按设置大小显示
if (rootViewLastVisibleHeight == 0) {
rootViewLastVisibleHeight &#