我有一个RelativeLayout
和一个EditText
,它下面有Button
。理想情况下,当用户单击EditText
并填充多行文本时,RelativeLayout
也会随着行数的增加而扩大。然而,我现在的行为是在EditText
的第一行填满之后,键盘开始覆盖其下面的Button
,并且在EditText
之后的3-4行文本之后,Button
不在键盘之下。有什么办法可以让我在键入文本的时候,整个布局的尺寸增大,使按钮保持在键盘上方?这里是我的代码:软键盘隐藏多行EditText下面的按钮?
的AndroidManifest.xml:
<activity
android:name="<Name of project>.activity.Comments"
android:configChanges="orientation|keyboardHidden"
android:label="Comments"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateHidden|adjustResize" />
Comments.xml:
<RelativeLayout
android:id="@+id/send_message"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_margin="4dp"
android:layout_alignParentBottom="true">
<EditText
android:fontFamily="sans-serif"
android:id="@+id/write_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:gravity="left"
android:textSize="16sp"
android:textColor="@color/black"
android:cursorVisible="false"
android:textColorHint="@color/material_color_grey_300"
android:hint="@string/commentBack"
android:background="@drawable/edittext_bg"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLength="200"
android:scrollHorizontally="false" />
<Button
android:fontFamily="sans-serif-medium"
android:id="@+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/colorPrimary"
android:layout_marginTop="8dp"
android:text="@string/send"
android:background="@null"
android:layout_below="@id/write_comment"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:textAllCaps="false" />
</RelativeLayout>
我已经尝试添加android:isScrollContainer="true"
以为这样就可以创建一个滚动容器的EditText
如此这将有助于扩大布局,但似乎没有工作。任何帮助,将不胜感激。谢谢!
编辑:已在整个布局基于以下答案:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
android:id="@+id/comments_layout">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/comments_appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_alignParentTop="true"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:id="@+id/comments_listview"
android:layout_height="match_parent">
<ListView
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rv_view_comments">
</ListView>
<TextView
android:layout_below="@id/rv_view_comments"
android:gravity="center_horizontal"
android:padding="16dp"
android:textSize="16sp"
android:id="@+id/empty_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:text="@string/noComments" >
</TextView>
<include layout="@layout/include_progress_overlay"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/send_message"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_margin="4dp"
android:layout_alignParentBottom="true">
<EditText
android:fontFamily="sans-serif"
android:id="@+id/write_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:gravity="left"
android:textSize="16sp"
android:textColor="@color/black"
android:cursorVisible="false"
android:textColorHint="@color/material_color_grey_300"
android:hint="@string/commentBack"
android:background="@drawable/edittext_bg"
android:inputType="textMultiLine"
android:isScrollContainer="true"
android:maxLength="200"
android:scrollHorizontally="false" />
<Button
android:fontFamily="sans-serif-medium"
android:id="@+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/colorPrimary"
android:layout_marginTop="8dp"
android:text="@string/send"
android:background="@null"
android:layout_below="@id/write_comment"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:textAllCaps="false" />
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
编辑:按照Jaydroider的要求,我已经包括照片,以显示我的问题。如果我可以做一个GIF什么的,如果我增加更多的文字我EditText
领域,Send
按钮将键盘下方消失,除非我从EditText
删除文本中,'发送不能推:
编辑:我也展示了如何滚动到我的ListView
的底部,当我点击EditText
这里,如果这有帮助。
public void setupComment(final EditText comment) {
//Once we send the post, we want to scroll to bottom of listview
comment.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
comment.setImeOptions(EditorInfo.IME_ACTION_DONE);
resetKeyboardSettings();
}
return false;
}
});
//Hide the cursor until view is clicked on
View.OnTouchListener onTouchListener = new View.OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println("Touched");
if (v.getId() == comment.getId()) {
comment.setCursorVisible(true);
}
commentsView.postDelayed(new Runnable() {
@Override
public void run() {
commentsView.smoothScrollToPosition(commentsView.getAdapter().getCount());
}
}, 750);
return false;
}
};
comment.setOnTouchListener(onTouchListener);
}
当我检查你的布局时,我只能看到'List View'没有任何其他的小部件。请详细说明。 –
@jaydroider我已经更新了上面的代码来演示我的问题。希望有帮助。它是在编辑说'编辑:添加在整个布局根据回答如下:' – user1871869
是的,我已经检查过我的布局我需要澄清'编辑文本'和'按钮'将显示在哪里。目前我只能看到'List View'。 –