Android 软键盘打开时如何滚动至底部滚动视图
当编辑文本请求焦点和软键盘打开时,我需要滚动查看滚动到底部。 以下是我的xml代码:Android 软键盘打开时如何滚动至底部滚动视图,android,scrollview,android-softkeyboard,Android,Scrollview,Android Softkeyboard,当编辑文本请求焦点和软键盘打开时,我需要滚动查看滚动到底部。 以下是我的xml代码: <ScrollView android:id="@+id/transfer_scroller" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/blue_500" android:fillViewport="true
<ScrollView
android:id="@+id/transfer_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue_500"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_senderLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:id="@+id/ll_selectRec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_receiverLayout"
android:visibility="gone"
android:layout_below="@id/cv_transfer_senderLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:id="@+id/transfer_layout_ll_receivers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cv_transfer_setAmount"
android:visibility="gone"
android:layout_below="@id/cv_transfer_receiverLayout"
style="@style/CardViewStyle.Transaction">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:id="@+id/transfer_layout_et_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:digits="0123456789"
android:hint="@string/hint_ed_ll_money"
android:inputType="phone"
android:gravity="center"
android:maxLength="7"
android:singleLine="true"
android:textColor="@color/gray_400"
android:textSize="@dimen/font_summ" >
</EditText>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
但这没用。键盘已打开并覆盖布局的其余部分。。。
有什么想法吗?我不确定您的问题是什么,是scrollview无法到达底部,还是您不希望软键盘覆盖scrollview 对于第一个问题,您可以在处理程序中尝试以下操作:
mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
或者,您可以按如下方式更改代码:
if (scroll == null || inner == null) {
return;
}
int offset = inner.getMeasuredHeight() - scroll.getHeight();
if (offset < 0) {
offset = 0;
}
scroll.scrollTo(0, offset);
第二种方法:在AndroidManifest.xml的活动中编写以下内容:
android:windowSoftInputMode="adjustPan"
你说的内部是什么意思?public static void scroll tobottomfinal View scroll,final View internal{Handler mHandler=new Handler;mHandler.postnew Runnable{public void run{if scroll==null | | | internal==null{return;}int offset=internal.getmeasuredhight-scroll.getHeight;if offset<0{offset=0;}scroll.scrollTo0,offset;}};}公共静态无效scrollToBottomfinal View scroll,final View innerView scroll表示scrollview的外层,inner位于scrollview的内层。scrollview的内容都在其内部视图中。希望这能帮助你。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
android:windowSoftInputMode="adjustPan"