键盘出现时如何滚动我的整个布局? [英] How to scroll my entire layout when the keyboard appears?
问题描述
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/defaut_padding" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/defaut_padding"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="10dp"
android:background="@drawable/watermark" />
<ProgressBar
android:id="@+id/bitmap_loading"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible" />
</FrameLayout>
<FrameLayout
android:id="@+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/photo"
android:layout_marginLeft="15dp"
android:layout_marginTop="-30dp"
android:background="@android:color/white"
android:padding="@dimen/smallest_padding" >
<ImageView
android:id="@+id/user_picture"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/anonymous_user" />
</FrameLayout>
<TextView
android:id="@+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/user"
android:layout_marginLeft="@dimen/defaut_padding"
android:layout_toRightOf="@id/user"
android:text="@string/anonymous_user"
android:textStyle="bold" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/input_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:padding="5dp"
android:layout_marginBottom="@dimen/defaut_padding"
android:background="@drawable/textfield"
android:hint="@string/description_hint"
android:focusableInTouchMode="true"
android:maxLines="3"
android:scrollbars="vertical" />
<Button
android:id="@+id/publish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/confirm_button_selector"
android:text="@string/confirm_button"
android:textColor="@android:color/white"
android:textSize="@dimen/big_text_size"
android:textStyle="bold" />
</FrameLayout>
</LinearLayout>
</ScrollView>
当我开始在 EditText 上进行数字时,我想在软键盘出现时滚动它.我怎样才能做到这一点?当前滚动有效,但键盘出现在按钮上方,我想要键盘上方的按钮
I want to scroll it when the soft keyboard appears when I start to digit at the EditText. How can I do this? Currenty the scroll works, but the keyboard appears above the button, and I want the button above the keyboard
当用户在 EditText 中单击时,我尝试移动滚动条,执行如下操作:
I've tried to move the scrool when the user clicks in the EditText, doing something like this:
mSv.scrollTo(0, mSv.getBottom());
其中 mSv 是我的 ScrollView
where mSv is my ScrollView
但它只有在用户第二次点击 EditText 时才有效.
But it only works when the user clicks in the EditText at the second time.
感谢您的帮助.
推荐答案
尝试将键盘更改为平移而不是调整大小.您可以在 AndroidManifest.xml 文件中执行此操作,为您的特定 Activity
添加以下内容
Try to change your Keyboard to pan instead of resize. You could do that in your AndroidManifest.xml file, for your particular Activity
, add the below to it
android:windowSoftInputMode="adjustPan"
或
如果你想隐藏,那么:
EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editTextSearch.getWindowToken(), 0);
如果要显示:
EditText editTextSearch = (EditText) findViewById(R.id.editTextSearch);
editTextSearch.requestFocus();
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
这篇关于键盘出现时如何滚动我的整个布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!