具有多行和adjustPan windowSoftInputMode的Android编辑文本框

3
在我目前正在开发的聊天应用中,我有一个带有编辑文本的底部栏,以下是我的编辑文本布局:
 <RelativeLayout
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
>

  <EditText
      android:id="@+id/edt_send_message"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_gravity="center_vertical"
      android:layout_marginStart="12dip"
      android:layout_toEndOf="@+id/img_add"
      android:layout_toStartOf="@+id/img_send_message"
      android:background="#00000000"
      android:hint="@string/send_message"
      android:inputType="textCapSentences|textMultiLine|textAutoComplete|textAutoCorrect"
      android:isScrollContainer="false"
      android:lineSpacingMultiplier="1.2"
      android:maxHeight="120dip"
      android:minHeight="45dip"
      android:paddingBottom="19dip"
      android:paddingTop="19dip"
      android:scrollbars="none"
      android:textColorHint="@color/colorPrimary"
      android:textSize="16sp">
  </EditText>

<!-- OTHER STUFF -->

</RelativeLayout>

当我开始输入时,多行文本框很好地启动了。

但是当我把焦点移到第一行时,编辑文本的一部分会移动到键盘下面。

enter image description here

我知道使用 adjustResize 会解决问题,但是我不能使用它,因为我有一个位图并且它被压缩了。所以我不能使用 adjustResize

需要帮助,谢谢您提前。


你尝试过在位图上添加属性android:scaleType="fitCenter"的同时使用adjustResize吗? - KoalaKoalified
2个回答

0
有趣的问题,我能想到的唯一解决方法就是这个hacky的解决方案。而且我不确定这200毫秒对于速度较慢的设备是否足够。但也许它能帮到你。
final EditText txtEdit = (EditText) findViewById(R.id.edt_send_message);
        txtEdit.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                final int sel = txtEdit.getSelectionStart();
                txtEdit.setSelection(txtEdit.getText().length());
                txtEdit.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        txtEdit.setSelection(sel);
                    }
                }, 200);
            }
        });

-1

我认为你可以在这个页面的答案中找到你的答案,但作为一项普遍法律,我复制了解决方案,以便我的答案不仅仅是一个链接。

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_width="0px" 
    android:layout_height="0px"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" 
    android:nextFocusLeft="@id/autotext"/>

如果不行的话,请告诉我。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接