聚焦时如何缩放EditText?

时间:2019-08-26 16:00:56

标签: java android android-layout kotlin layout

我有一个ScrollView,其中包含一个CustomView。在那个CustomView中,我可以有许多这样的EditText:

First

当我聚焦一个EditText时,我想要缩放此EditText,以便此EditText位于屏幕的中央,并采用与屏幕相同的宽度。

预期结果:

enter image description here

对不起,我的英语不好,谢谢您的帮助!

1 个答案:

答案 0 :(得分:0)

EditText具有 setOnFocusChangeListener ,用于查看EditText何时接收和释放焦点。

     editText.setOnFocusChangeListener(new OnFocusChangeListener() {
     @Override
     public void onFocusChange(View view, boolean hasFocus) {
          if (hasFocus) {
              //Dynamically resize EditText to match device width
          } else {
              //Dynamically resize EditText to match previous width with margin
          }
      }
  });

您可以像本link一样使用LayoutParams动态更改EditText的宽度和高度。